Python Forum
Using break to exit a loop help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using break to exit a loop help
#1
Hi all, I'm having a problem trying to run this program. I was messing around with a similar program I tried to create and it would not work. So i took this one right out of my book and I the get the same outcome. Any help would be great ty
prompt = "\nPlease enter the name of a city you have visited: "
prompt += "\n(enter 'quit' when you are finished.) "

while True:
    city = input(prompt)

    if city == 'quit':
        break
    else:
        print("id love to go to " + city.title() + "!")
Please enter the name of a city you have visited:
(enter 'quit' when you are finished.) tbay
Traceback (most recent call last):
  File "input.py", line 30, in <module>
    city = input(prompt)
  File "<string>", line 1, in <module>
NameError: name 'tbay' is not defined
Reply


Messages In This Thread
Using break to exit a loop help - by JJG - Dec-08-2017, 10:49 PM
RE: Using break to exit a loop help - by wavic - Dec-08-2017, 10:59 PM
RE: Using break to exit a loop help - by JJG - Dec-09-2017, 01:50 AM
RE: Using break to exit a loop help - by wavic - Dec-09-2017, 02:30 AM
RE: Using break to exit a loop help - by JJG - Dec-09-2017, 03:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python difference between sys.exit and exit() mg24 1 1,920 Nov-12-2022, 01:37 PM
Last Post: deanhystad
  Code won't break While loop or go back to the input? MrKnd94 2 1,037 Oct-26-2022, 10:10 AM
Last Post: Larz60+
  How to break out of a for loop on button press? philipbergwerf 6 1,862 Oct-06-2022, 03:12 PM
Last Post: philipbergwerf
  break out of for loop? User3000 3 1,513 May-17-2022, 10:18 AM
Last Post: User3000
  Asyncio: Queue consumer gets out of while loop without break. Where exactly and how? saavedra29 2 2,748 Feb-07-2022, 07:24 PM
Last Post: saavedra29
  While loop doesn't exit KenHorse 3 2,070 Jun-20-2021, 11:05 PM
Last Post: deanhystad
  tkinter control break a while loop samtal 0 2,434 Apr-29-2021, 08:26 AM
Last Post: samtal
  Cannot 'break' from a "for" loop in a right place tester_V 9 4,066 Feb-17-2021, 01:03 AM
Last Post: tester_V
  How to break a loop in this case? Blainexi 10 7,391 Sep-24-2020, 04:06 PM
Last Post: Blainexi
  Exit Function - loop Tetsuo30 2 2,108 Sep-17-2020, 09:58 AM
Last Post: Tetsuo30

Forum Jump:

User Panel Messages

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