-1

scenario2(outcome) function calls sget_choice3 one so it either prints an outcome based on the users choice.

I want function to loop and ask for input twice if the Users selection is 0 (correct one is 1 and 0 is just a branch of it).

s2option_list3 =['Try to force it', 'Examine the door']

    def sget_choice3(s2option_list3):
        i = -1
        while i <= 0:
            print s2option_list3
            choice3 = raw_input("> ")
            for i, opt in enumerate(s2option_list3):
                if opt in choice3:
                    i = i + 1
                    return i 
                else:
                    i = i + 2
                    return i             

            print "You need to select one of the given actions"

def scenario2_exit(outcome): 
    print outcome
    choice = outcomes[0]

    if outcome in choice:
        print "conversation"

        res3 = sget_choice3(s2option_list3)

        if res3 == 0:
            print "You try to force it but without any luck. However you do notice a little button on the left corner. "

        else:
            print "A small panel comes out, seems to be requesting a code. " 
            print "conversation"            

    else:
        print "conversation"
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140

1 Answers1

1

Your issue appears to be in this line:

for i, opt in enumerate(s2option_list3):

When you use enumerate like that, it is overwriting your value for i (-1 at the time) with the index of the enumeration (0 for the first option and 1 for the second). I'm not sure why you are trying to use the enumeration at all.

Without giving you too much advice on how to restructure your program, a simple fix could be something like:

for opt in s2option_list3:
grovesNL
  • 6,016
  • 2
  • 20
  • 32