确定整数是否在其他两个整数之间?

本文翻译自:Determine Whether Integer Is Between Two Other Integers?

How do I determine whether a given integer is between two other integers (eg greater than/equal to 10000 and less than/equal to 30000 )? 如何确定给定的整数是否在其他两个整数之间(例如,大于/等于10000且小于/等于30000 )?

I'm using 2.3 IDLE and what I've attempted so far is not working: 我正在使用2.3 IDLE,到目前为止,我一直没有尝试:

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

#1楼

参考:https://stackoom.com/question/vBTD/确定整数是否在其他两个整数之间


#2楼

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

#3楼

Your operator is incorrect. 您的操作员不正确。 Should be if number >= 10000 and number <= 30000: . if number >= 10000 and number <= 30000: Additionally, Python has a shorthand for this sort of thing, if 10000 <= number <= 30000: . 另外, if 10000 <= number <= 30000: ,Python就是这种事情的简写形式。


#4楼

if 10000 <= number <= 30000:
    pass

#5楼

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. 实际检查数字是否同时大于10000和30000。

Assuming you want to check that the number is in the range 10000 - 30000, you could use the Python interval comparison: 假设您要检查数字范围在10000-30000之间,可以使用Python间隔比较:

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

This Python feature is further described in the Python documentation . Python文档中进一步描述此Python功能。


#6楼

>>> 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值