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 trialBegana Choi
Courses Plus Student 13,126 Pointsquestion about try block
hello, I have a question about try block. in this video, why do we put only
try:
amount_of_ticket = int(amount_of_ticket)
this line of code? why not like this?
try:
amount_of_ticket = input("Hello, {}! How many tickets would you like? ".format(user_name))
amount_of_ticket = int(amount_of_ticket)
can somebody let me know more clearly about try block? thank you.
1 Answer
Christian Beckett
11,123 Pointswhen you are using try. your mission is to prevent the user from using a number like -12. so in try you really just want to know the number. when you run try. you'll run the question "Hi {} how many tickets would you like" it would create an annoying algorithm plus its better to have the tickets by them self making it so when you try something else it wouldn't be as confusing now something like this wouldnt be bad tho.
try:
amount_of_ticket = input("Sorry about that {} Thats not a valid number. Please Try again").format(user_name)
amount_of_ticket = int(amount_of_ticket)
Begana Choi
Courses Plus Student 13,126 PointsBegana Choi
Courses Plus Student 13,126 PointsThank you ! Now I understood clearly
Christian Beckett
11,123 PointsChristian Beckett
11,123 PointsNp anymore questions feel free to ask me