Python Forum
Simple while loop only works on first attempt
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple while loop only works on first attempt
#1
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")
Reply
#2
typo in anwser = input()

>>> 'answer' == 'anwser'
False
Reply
#3
Its been a long day.

Many thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 2,027 Dec-18-2021, 02:38 AM
Last Post: knight2000
  My simple code don't works !! Nabi666 1 1,618 Sep-06-2021, 12:10 PM
Last Post: jefsummers
  Seemingly simple loop Weber585 7 3,518 Mar-21-2021, 07:19 PM
Last Post: jefsummers
  Simple Variable Saving in Loop DevDev 3 3,037 Mar-09-2021, 07:17 PM
Last Post: Fre3k
  simple for loop? gr3yali3n 3 2,538 Sep-22-2020, 05:35 AM
Last Post: buran
  IndexError in Project Euler attempt CRISPRmetoopls 3 2,323 Aug-10-2020, 10:00 AM
Last Post: perfringo
  Adding second message to simple loop error PythonGainz 2 2,096 Apr-06-2020, 11:55 AM
Last Post: PythonGainz
  Simple code works in Jupyter but not VS Code Matt_O 2 3,942 Nov-17-2019, 01:15 AM
Last Post: Matt_O
  simple key value loop help siten0308 4 2,447 Jun-25-2019, 02:53 PM
Last Post: siten0308
  Can someone fix this simple code so it works? DragonG 1 2,226 Nov-03-2018, 02:59 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020