我到处寻找我的问题的答案,我仍然无法理解!答案可能太简单但我无法得到它,也许是因为我刚刚回到Python ......
无论如何,我想创建一个while循环,这样在用户输入'y'或'n'之前,问题就会不断被问到。这就是我所拥有的:
while True: # to loop the question
answer = input("Do you like burgers? ").lower()
if answer == "y" or "n":
break
老实说我太困惑了,所以我求求别人的帮助:)。
答案 0 :(得分:5)
while True: # to loop the question
answer = input("Do you like burgers? ").lower()
if answer == "y" or answer == "n":
break
答案 1 :(得分:3)
你的病情有误。此外,如果您使用的是Python 2.x,则应使用raw_input
(否则您需要输入"y"
而不是y
,例如):
while True: # to loop the question
answer = raw_input("Do you like burgers? ").lower()
if answer == "y" or answer == "n":
break