Dejan Delev461 Points
So I followed Craig's code and wanted to test it out in the end with all the possible errors, so when I used "blue" as an answer to How many tickets I would like to buy, it printed:
How many tickets would you like to buy, Johnny? blue
Oh no, we ran into an issue. invalid literal for int() with base 10: 'blue'. Please try again!
Pedro Cabral19,560 Points
When you write blue, the code tries to convert the string "blue" to an int which is not valid and thus throws a ValueError which you catch in your except block and handle it by printing your custom message with the exception message. What was the result you were expecting?
The error in your code actually occurs in the line before your if statement, so the interpreter doesn't read that if statement before it exits the try block and goes into the exception block. The type of error is still a ValueError, so it is caught by the "except ValueError..." block. However, the error is a separate ValueError than what the if statement would have raised. Since it's not the ValueError that the if statement raises, it doesn't have the message you gave to the ValueError in the if statement. Rather, it has the default error message for ValueErrors involving invalid int coercions.
sulaiman abouabdah5,314 Points
Check out this solution: https://teamtreehouse.com/community/when-doing-the-valueerror-as-err-it-doesnt-solve-the-how-many-ticket-do-you-want-blue-error-we-solved-earlier Using isDigit solves the problem