[Solved] Python list how to identify the given number is in the range Challenge Question [closed]


You may iterate on the element of your list, and for each test the expression value-10 < x and x < value+10 that can be written in once in python value-10 < x < value+10

def search_numbers(values, x):
    for value in values:
        if value - 10 < x < value + 10:
            print(f"Ok: {value}-10 < {x} < {value}+10")
            return True
    return False

mylist = [100, 30, 400, 340, 230, 160, 25]
print(search_numbers(mylist, 239))  # True
print(search_numbers(mylist, 243))  # False

solved Python list how to identify the given number is in the range Challenge Question [closed]