我在这发现了一个线程,但我没有任何运气得到它的工作。两个值之间的蟒整数
min = 9
max = 10
a = ['8','9','10','11']
for x in a:
if max >= x > min:
print 'one'
else:
d = (max >= x > min)
print d, x
if (x > min >= max):
#if (min <x>= max):
print x
else:
print x, ' is equal to or greater than', max
输出:
False 8
8 is equal to or greater than 10
False 9
9 is equal to or greater than 10
False 10
10 is equal to or greater than 10
False 11
11 is equal to or greater than 10
这个线程working code?表示语法必须是:
if 10000 <= number <= 30000:
pass
我已经试过迹象我能想到的每一种组合,和回报总是对所有人来说都是对的,这是错误的。
我也试过这个(更长)代码:
min = 9
max = 10
a = ['8','9','10','11']
for x in a:
print 'X is:', x
if int(x) == max:
print 'max found:', x
elif int(x) < max:
if int(x) > min:
print 'min:', x
elif int(x) < min:
print 'under range', x
else:
print 'out of range', x
与产出也意外的,因为我希望赶上的所有情况:
X is: 8
X is: 9
X is: 10
max found: 10
X is: 11
out of range 11
唉!我怎样才能正确地检查所有项目,然后返回,超过我的最小值,最大值?
你比较字符串和整数。 – vaultah
谢谢!检查第二位代码。 – shawn
没有> min和 ='和'<='? –