The Python Oracle

Determine whether integer is between two other integers

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Digital Sunset Looping

--

Chapters
00:00 Determine Whether Integer Is Between Two Other Integers
00:21 Answer 1 Score 73
00:31 Accepted Answer Score 1576
00:42 Answer 3 Score 40
00:58 Answer 4 Score 136
01:04 Thank you

--

Full question
https://stackoverflow.com/questions/1362...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python

#avk47



ACCEPTED ANSWER

Score 1576


if 10000 <= number <= 30000:
    pass

For details, see the docs.




ANSWER 2

Score 136


>>> r = range(1, 4)
>>> 1 in r
True
>>> 2 in r
True
>>> 3 in r
True
>>> 4 in r
False
>>> 5 in r
False
>>> 0 in r
False



ANSWER 3

Score 73


Use if number >= 10000 and number <= 30000:. Alternately, Python has a shorthand for this sort of thing, if 10000 <= number <= 30000:.




ANSWER 4

Score 40


To check that the number is in the range 10000 - 30000, use the Python interval comparison:

if 10000 <= number <= 30000:
    print ("you have to pay 5% taxes")

This Python feature is further described in the Python documentation.