Python Forum
Simple while loop only works on first attempt - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Simple while loop only works on first attempt (/thread-19275.html)



Simple while loop only works on first attempt - jsb83 - Jun-20-2019

Hello all

New to python any help much appreciated. When I run the code below if I enter No on the first attempt python prints "PLEASE CAN I HAVE ANOTHER ONE" AS EXPECTED. If I then enter yes on the next cycle it does not print thanks mum it keeps looping back to "Please can I have another one". Can some one help.

print("Mum can I have an ice cream?")

answer= input()

while answer == "No":
    print("Please can I have one")
    

    anwser = input()

    
print("Thanks mum")



RE: Simple while loop only works on first attempt - Yoriz - Jun-20-2019

typo in anwser = input()

>>> 'answer' == 'anwser'
False



RE: Simple while loop only works on first attempt - jsb83 - Jun-20-2019

Its been a long day.

Many thanks