问个白痴问题,python 中如何定义一个范围 如:number=input('Enter Your Number:')if number == int(1):print 'yes'如何将int(1)定义成一个范围如1至20,让输入1至20都显示yes还有怎么能在这个代码运行完以后再从头运行
1 回答
狐的传说
TA贡献1804条经验 获得超3个赞
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]添加回答
举报
0/150
提交
取消
