此函数的目的是检查用户的输入,确定其是否在列表中,如果不在列表中,则告诉用户“选择给定选项之一”。你知道吗
问题是它两次要求我输入。当我选择“接近出口门”选项时,它会再次循环并请求输入,当我再次输入相同的选项时,也就是当我得到结果时(这导致dead()函数没有复制到这里以保持简短)。尝试了几种方法,比如添加一个关闭循环的条件,并试图使While为False,这样它就停止了,但是没有起作用。另外,感谢用户khelwood为我提供了这个替代方案并简化了我的程序。你知道吗
太久没读了?循环要求输入两次,无法修复。
这是密码。你知道吗
s2option_list =['Approach exit door', 'Check for vital signs']
def sget_choice(s2option_list):
while True:
print s2option_list
choice = raw_input('> ')
for i, opt in enumerate(s2option_list):
if opt in choice:
return i
else:
print "You need to select one of the given options."
def scenario2(response):
print response
print "Conversation"
print "Conversation"
print "Conversation"
sget_choice(s2option_list)
if sget_choice(s2option_list)==0:
dead("Conversation")
else:
print "Conversation"
sget_choice2(s2option_list2)
相关问题 更多 >
编程相关推荐