Is there a greater than but less than function in python?
In Python you can even write
while 10 < a < 20:
do_smth()
while 10 < a < 20:
whatever
This doesn't work in most languages, but Python supports it. Note that you should probably be using a for
loop:
for a in range(11, 20):
whatever
or if you just want to test a single number rather than looping, use an if
:
if 10 < a < 20:
whatever
Be careful with the boundary conditions. When your first loop ends, a
is set to 10
. (In fact, it's already set to 10 when you print the last "less than 10" message.) If you immediately check whether it's greater than 10, you'll find it's not.