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.
Erik EmbervinePython Development Techdegree Student 2,088 Points
is Craig's code in the masterticket.py program considered "clean" or "complete"?
after Craig completes his finishing touches to the code in this video, i ran the code again. when i enter a string value to answer the question "How many tickets would you like?", it outputs not only the "Sorry not valid" print statement in the "except ValueError as err" block, which makes sense, but it also prints out the contents of the "err" variable: "invalid literal for int() with base 10: [string]". is this what Craig intended? i assume we don't want users to see this.. maybe i missed something? i came up with my own solution to handle the message, but was curious if i am mistaken, or if this was an oversight or by design? other?
Steven Parker218,692 Points
I think you can expect that every course exercise will be designed to illustrate the lesson principles but none will be examples of fully implemented and rigidly tested ready-to-publish software products.
The fact that all the examples may be efficiency optimized, UX enhanced, or given additional features can become opportunities for extra practice if you want some.
As to improvements, this line of the code caught my eye:
if purchaseConfirmation.startswith('y' or 'Y'):
You can't combine terms with logic operators, only complete expressions. This won't detect a capital "Y". But you can do it with complete expressions like this:
if purchaseConfirmation.startswith('y') or purchaseConfirmation.startswith('Y')::
But perhaps more efficiently like this:
Also, testing for ticketCount above 100 or less than 0 isn't necessary, since neither is a possible condition.