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.

Python Python Basics All Together Now Handle Exceptions

Mark Kohner
Mark Kohner
1,760 Points

repetitive looping necessary?

Why do we put num_tickets = int(num_tickets) in the while loop?

while tickets_remaining >= 1: print("There are {} tickets remaining.".format(tickets_remaining)) num_tickets = input("How many tickets would you like, {}? ".format(name)) num_tickets = int(num_tickets)

so each iteration it would have to re-run co-ercing num_tickets into an int right? Is there a better process for this?

1 Answer

Steven Parker
Steven Parker
215,939 Points

That's a type conversion — it's not related to the looping, nor is it repetitive.

The "input" statement returns a string, so the "int" function is used to convert it into a number to make it possible to use it in value comparisons and math operations.