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
194,826 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.