You are here: Home / Topics / Write a Python program to test whether a number is within 100 of 1000 or 2000

Write a Python program to test whether a number is within 100 of 1000 or 2000

Filed under: Python on 2023-09-23 06:49:09

def near_thousand(n):
     return ((abs(1000 - n) <= 100) or (abs(2000 - n) <= 100))
print(near_thousand(1000))
print(near_thousand(900))
print(near_thousand(800))   
print(near_thousand(2200))     

Output:

True                                        
True                                                                 False                                                               False 

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.