如果答案不同于1或2,我需要python继续询问raw_input。
这里的例子是:
print """What do you want me to do?
1) Press 1 if you want to .....
2) Press 2 if you want to ....."""
while True:
answer1 = raw_input(" => ")
if (answer1 == 1):
....
....
elif (answer1 == 2):
....
....
elif (answer1 != 1 or 2) or answer1.isalpha():
print "I need 1 or 2"
问题是如果用户输入1或2,python也会继续询问raw_input。 我哪里错了?
答案 0 :(得分:0)
如果答案为break
或if
,则应在elif
和1
块中添加2
语句,以打破while循环。< / p>
示例 -
if (answer1 == 1):
....
....
break
elif (answer1 == 2):
....
....
break