所以,我为学校做了一个调查,我必须制作一个程序,用调查中的信息打印有多少人选择了第二个问题的第三个选项(c(。然后我不得不根据调查数据打印出参加调查的人数。然后我不得不问他们想要查看哪个问题的结果。如果他们输入的数字不在1、2、3的范围内,则应该打印"0";这不是问题"然后返回到相同的代码:
choice = int(input("Which question's results would you like to see? "))
但它只是继续打印";这不是一个问题"一次又一次,直到系统关闭我的控制台。这是我的全部代码:
print ("1 person that took the survey said they like C (sandwich)")
print ("7 people took the survey")
choice = int(input("Which question's results would you like to see? "))
while choice not in [1,2,3]: print ("That isn't a question!")
choice = int(input("Which question's results would you like to see? ")
如果你想知道我说的是什么调查,你可以在这里找到:https://docs.google.com/forms/d/e/1FAIpQLSdvKS6JsLzT4_bIkMOq6IOIn1c_1tsCG78bm4f4rr_5P75rMA/viewform?usp=sf_link
因为您永远不会退出while语句,所以永远不会更新选项值,代码应该是:
print ("1 person that took the survey said they like C (sandwich)")
print ("7 people took the survey")
choice = int(input("Which question's results would you like to see? "))
while choice not in [1,2,3]:
print ("That isn't a question!")
choice = int(input("Which question's results would you like to see? "))
尝试这个轻微的修改:
print ("1 person that took the survey said they like C (sandwich)")
print ("7 people took the survey")
choice = None
while choice not in [1, 2, 3]:
choice = int(input("Which question's results would you like to see? "))
print ("That isn't a question!")