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 trialAnthony Grodowski
4,902 PointsCode 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
adrian miranda
13,561 PointsThis 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
4,902 PointsAnthony Grodowski
4,902 PointsThank 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?
Anthony Grodowski
4,902 PointsAnthony Grodowski
4,902 Pointsalright, handled it by myself!