在这段代码中,我尝试调用一个函数。另一方面,它不按我希望的方式工作,因为它保持循环,即使我将循环条件 options_secondscenario [0] 从0更改为1环。我想要做的是移动到third_scenario()函数。提前谢谢。
options_secondscenario = ['Whats going on out there?', 'So what now?']
def third_scenario():
print "This is the third scenario"
choiceselection2 = raw_input("> ")
if choiceselection2 == 1:
print "stay"
else:
print "leave"
def dead():
print "You are dead"
exit()
def second_scenario():
print "Conversation 1"
print "Conversation 2"
print "Conversation 3"
print options_secondscenario
choices = options_secondscenario[0]
while choices == options_secondscenario[0]:
choiceselection = raw_input("> ")
if choiceselection == 'Whats going on out there?':
print "Conversation 4"
elif choiceselection == 'Whats up':
print "Nothing"
elif choiceselection == 'what is that':
print "I dont know"
elif choiceselection == 'is':
dead()
else:
third_scenario()
choices == options_secondscenario[1]
second_scenario()
答案 0 :(得分:2)
您试图在循环后更改choices
var(检查缩进)。所以while循环永远不会有机会达到这个陈述。
此外,您正在使用比较运算符==
而非分配运算符=
,如下所示:
choices = options_secondscenario[1]
该行应该在你的while循环中的某个地方。检查你的缩进。