The purpose of this function is to check the input of the user, determine if its in the list, and, if not, tells the user to ''Select one of the given options''.
The issue with it is that it asks me for input twice. When I select option ''Approach exit door'' it loops again and asks for input, when I enter the same option again thats when I get the result (which leads to dead() function not copied here to keep this short). Tried several things, like adding a condition that closes the loop and tries to make the While False so it stops, but it didnt work. Also, thanks to user khelwood who provided me with this alternative and simplified my program.
too long didnt read? Loop asks for input twice, cant fix it.
Heres the code.
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)
sget_choicetwo times inscenario2. Once before and one inside of theifstatement.== 0though, do you only accept one option?sget_choiceagain, your problem was you were calling the function twice, you need to just call once and store the return value and compare that or just useif sget_choice(s2option_list)==0once and forget the previous call