Question Description:Given a number n, return True if n is in the range 1..10, inclusive. Unless outsideMode is True, in which case return True if the number is less or equal to 1, or greater or equal to 10.in1to10(5, False)  **True**in1to10(11, False)  **False**in1to10(11, True)  **True**The link to the problem is here.Below is my first attempt.  Please feel free to review it based on best practices, style and any other efficient solution.def in1to10(n, outside_mode):    if(n>1 and n<10):        return not outside_mode    else:        return outside_mode or n is 10 or n is 1
Finding if a given number is in a given range based on a flag
python;beginner;programming challenge
Please feel free to review it based on best practices, style and any other efficient solution.@mjolka already provided a more natural alternative implementation I completely agree with: following the logic precisely as in the problem statement is natural and easy to understand. I think the reason why it's easier to understand than yours has to do with the fact that the ranges being evaluated in the 2 distinct cases depending on the value of outside_mode have an overlap on the values 1 and 10. If the two ranges were complements of each other, things would be simpler.As for style:if(n>1 and n<10):    return not outside_modeelse:    return outside_mode or n is 10 or n is 1The parentheses in the if condition are redundant.And PEP8 recommends to put spaces around operators, so this would be better:if n > 1 and n < 10:Even better is to use Python's kick-ass ... < ... < ... operator:if 1 < n < 10:Be careful with using is. In this example it works as expected, but if you try to use for non-primitive types, it might not give what you expect:>>> [1, 2] is [1, 2]False>>> (1, 2) is (1, 2)FalseUnless there is a specific reason to use is, I think you should use ==:return outside_mode or n == 10 or n == 1