【发布时间】:2012-10-10 21:34:00
【问题描述】:
如果没有正确满足条件,我如何让 Python 移动到 if 语句的顶部。
我有一个这样的基本 if/else 语句:
print "pick a number, 1 or 2"
a = int(raw_input("> ")
if a == 1:
print "this"
if a == 2:
print "that"
else:
print "you have made an invalid choice, try again."
我想要的是提示用户为此 if 语句做出另一个选择,而不必重新启动整个程序,但我对 Python 非常陌生,并且在任何地方都无法在线找到答案。
【问题讨论】:
-
你必须将整个东西包裹在一个循环中(通常是
while)。 -
那么会为我做吗?谢谢生病去研究,甚至不知道从哪里开始
-
@quantumSoup 像这样的时候,我想念 do-while 循环,不过很容易用常规的 while 循环来模拟
标签: python if-statement raw-input