Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics All Together Now Handle Exceptions

"Sorry Tickets are all sold out!" continues to loop when trying to request more than 100 tickets

OK so the title says what I'm seeing when executing the code, which is as follows:

https://w.trhou.se/oay9a61c88

Here is what I see when testing it out:

There are 100 tickets remaining

What is your name? Chris

How many tickets would you like, Chris? 120

On no. We ran into an issue. There are only 100 tickets remaining. Please try again.

Sorry the tickets are all sold out. :(

There are 100 tickets remaining. What is your name?

OK so why is this looping the way it is?

1 Answer

Steven Parker
Steven Parker
231,275 Points

If you want the program to stop, you can use a "break" statement after you've responded to the input (such as between lines 16 and 17). And if you want to start over, you could use a "continue" statement at the same place instead.

But if you don't do either, the code will continue at line 27 and print the "sold out" message before repeating.