【发布时间】:2020-06-28 18:05:23
【问题描述】:
如您所见,用户为年龄输入输入了 3 个以上的数字,这样是不正确的。 我想要的是在我的输入中获得有限的数字,我的意思是如果学生的数量是 3,那么如果用户的身高/体重/年龄超过 3,我该如何返回错误?
classAcounter=int(input("How many students? "))
classAlist=[]
height=input().split(" ")
weight=input().split(" ")
age=input().split(" ")
classAlist.append(height)
classAlist.append(weight)
classAlist.append(age)
print(classAlist)
#input:
3
175 170 183 188
70 68 83
18 19 18 19
output:
[['175', '170', '183', '188'], ['70', '68', '83'], ['18', '19', '18']]
【问题讨论】:
-
您需要进行布尔测试。查看 if 语句。
标签: python input split limit raiserror