Finding if a given number is in a given range based on a flag
The logic is confusing. A direct translation of the problem specification is possible, and clearer.

Let's deal with the first half of the problem:


  Given a number \$n\$, return True if \$n\$ is in the range \$1 ..10\$, inclusive.


Then it's natural to write:

def in1to10(n):
    return 1 &lt;= n &lt;= 10


Now we can deal with the second half:

def in1to10(n, outside_mode):
    if outside_mode:
        return n &lt;= 1 or n &gt;= 10
    return 1 &lt;= n &lt;= 10