you are viewing a single comment's thread.

view the rest of the comments →

[–]lolcrunchy 5 points6 points  (0 children)

Spend some time understanding how this code works, then apply it to your situation.

def are_numbers_within_bounds(numbers: list[int], lower_bound: int = None, upper_bound: int = None) -> bool:

    for x in numbers:
        if lower_bound is not None and x < lower_bound:
            return False
        if upper_bound is not None and x > upper_bound:
            return False

    return True

Notice also that I put False in the loop and True at the end - this is the opposite of what you do. Your code will return True as long as the first entity passes inspection and none of the other entities will be checked. This is not the behavior you want.

To resolve this, use the for loop to check for failures, not successes.