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 trialStefan Siljanovski
6,063 PointsWhen asked how many tickets I input negative number (-5) and still sold me tickets ?
It still sold me tickets after answering negative number (-5) and gave me a total due of -48 and increased the number of tickets for variable tickets_remaining to 105 . How do we prevent that from happening ?
1 Answer
Steven Parker
231,236 PointsThe original code only checks if the requested number is more than the remaining tickets. But you can easily add another check for a number that is too small:
if num_tickets < 1:
raise ValueError("We cannot sell less than 1 ticket!")
Stefan Siljanovski
6,063 PointsStefan Siljanovski
6,063 Pointshttps://w.trhou.se/bdee7xra0z
Steven Parker
231,236 PointsSteven Parker
231,236 PointsSo based on your snapshot, those two lines could be placed between lines 15 and 16 or between 17 and 18.