狐的传说
test=range(1,21)
while(1):
number=input("Enter your number:")
try:
if number in test:
print 'yes'
except:
pass
补充:
如果你要对一个序列进行映射,可以用map:
>>> x=range(1,21)
>>> y=map(int,x)
>>> y
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]