0

so I actually want the program to keep on asking the same question over and over again.

ans = 'wrong'
alive = True
while alive == True:
    answer = input("""

----What do you want to do?(walk, or rest)----

    """)
    while(ans == 'wrong'):
        if answer == 'walk':
            print("nice")
            ans = 'true'
        elif answer == 'rest':
            print("you slept with your monsters")
            ans = 'true'
        else:
            print("Invalid Answer. Walk or Rest")
            answer = input("""

----What do you want to do?(walk, or rest)----

    """)

it does ask the player the same question but the answer is now set. When I first input my answer, it works perfectly but the second time, the program just ignores the input and asks the same question.

I want it to actually process the next answers and not ignore them. Please help.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • What is the value of `ans`, when executing `while(ans == 'wrong')` for the first time ? – Luuk Aug 28 '22 at 12:39
  • its value is 'wrong' – Gabriel Floyd Alinday Aug 28 '22 at 12:41
  • You should set `ans = "wrong"` before the inner while-loop. – thebjorn Aug 28 '22 at 12:45
  • 1
    In your current code you never assign it a value, you need to debug your code, using [How to step through Python code to help debug issues?](https://stackoverflow.com/questions/4929251/how-to-step-through-python-code-to-help-debug-issues) or [Python debugging in VS Code](https://code.visualstudio.com/docs/python/debugging), or any other means.... – Luuk Aug 28 '22 at 12:46
  • It asks the same question and ignores one because you put two input methods You should put `break` after Invalid Answer, then remove the inner loop. Therefore remove the second input – OneCricketeer Aug 28 '22 at 12:50
  • @OneCricketeer I see, it works as intended now. Thanks – Gabriel Floyd Alinday Aug 28 '22 at 12:55

0 Answers0