Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics All Together Now Handle Exceptions

Anthony Grodowski
Anthony Grodowski
4,902 Points

Code not raising ValueError

https://w.trhou.se/ljqzn8k9gs Line 15 code doesn't work while putting larger number of tickets than available. What did I wrong? Also my code doesn't update tickets remaining value - it shows 100 all the time even if it should say that they're all sold out. TIA

1 Answer

This has a number of issues. First, in line 6, you say

tickets_remaining = (ticket_remaining - ticket_number)

Mostly in this script you refer to tickets_remaining, but on this line you also have ticket_remaining. I think you just typoed, and left the s out of tickets.

Also, the first time through this loop, ticket_number isn't even set. You shouldn't be subtracting it there. Try doing it right after you say SOLD. (Think about it. If someone said no, they didn't want to buy it, you would still do the subtraction.)

Line 6 should really throw an error in a modern python, it's odd that you aren't getting one.

Also, when you say:

        raise ValueError("There are only {} tickets remaining".format(ticket_number))

I think you mean to use tickets_remaining, not ticket_number

Good luck!

Anthony Grodowski
Anthony Grodowski
4,902 Points

Thank you Adrian! I've made a couple of changes but now I face a problem, which appeard while trying to improve my code. (https://w.trhou.se/tc2bkyh1ty)

That's how program is running while putting too large number of tickets:

"Welcome to our aplication! What's your name? Anthony
Hello, Anthony!
How many tickets would you like to buy? 900
Oh no! There's an issue! There are only 900 tickets remaining. Please try again
There are 100 tickets remaining."

As you can see it puts ticket_number in the sentence telling how many tickets are remaining instead of tickets_remaining. What have I done wrong?