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.

Begana Choi
Courses Plus Student 13,124 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,121 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,124 PointsBegana Choi
Courses Plus Student 13,124 PointsThank you ! Now I understood clearly
Christian Beckett
11,121 PointsChristian Beckett
11,121 PointsNp anymore questions feel free to ask me