0

I'm a beginner in Python. I've tried using the 'while' loop. I need the code to allow the user to reattempt the question after their previously incorrect guess. After the first correct try, it says what I want it to say but after the first wrong try, the correct answer is given as incorrect. How do I solve this and what am I doing wrong?

    key = input("Choose a place and see if your guess is correct! ")
    if key == ("bed"):
        print("Congratulations! You are correct and will now progress to room 2.")
    while key != ("bed"):
        input("Unfortunately your guess is incorrect. Try again. ")        ```

2 Answers2

2

First of all you need to indent the 2nd line. Second of all the loop can't work because you say that the loop should stop when the key is "bed" but you do not change the key. The 4th line should be: key = input("Unfortunately your guess is incorrect. Try again. ") Of course you need to put your if statement in the while loop.

0
while(True):
if key == ("bed"):
print("Congratulations! You are correct and will now progress to room 2.")
False
else:
key = input("Unfortunately your guess is incorrect. Try againg.")

maybe try it like "this"?