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 trialMark Kohner
1,760 Pointsrepetitive 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
231,269 PointsThat'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.