While loops, comparing more than one value

左心房为你撑大大i 提交于 2019-12-02 13:51:19

If you have a condition of number != '1' or number != '2', one of those conditions will always be true, so it'll never break out of the loop. Try while number not in ('1', '2', '3') instead.

As mentioned, you used or instead of and. But the in operator may be a better choice:

number=input("Would you like to eat 1. cake 2. chocolate 3. sweets: ")
while number not in ("1", "2","3"):
    number=input("Please input a choice [1,2,3]")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!