Determine Whether Integer Is Between Two Other Integers?

前端 未结 11 964
猫巷女王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:39

    Suppose there are 3 non-negative integers: a, b, and c. Mathematically speaking, if we want to determine if c is between a and b, inclusively, one can use this formula:

    (c - a) * (b - c) >= 0

    or in Python:

    > print((c - a) * (b - c) >= 0)
    True
    

提交回复
热议问题