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!

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 trial

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
227,167 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.