Determine Whether Integer Is Between Two Other Integers?

前端 未结 11 965
猫巷女王i
猫巷女王i 2020-11-22 15:07

How do I determine whether a given integer is between two other integers (e.g. greater than/equal to 10000 and less than/equal to 30000)?

I\

11条回答
  •  无人共我
    2020-11-22 15:44

    Your code snippet,

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

    actually checks if number is larger than both 10000 and 30000.

    Assuming you want to check that the number is in the range 10000 - 30000, you could 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.

提交回复
热议问题