Python Python Basics All Together Now Branch and Loop

victorvillaplana
victorvillaplana
11,582 Points

Tickets remaining don't reset after running the code

Hello! I ran my code until the tickets were sold out. Now, when a try to run the program again in the console, I always see that the tickets are sold out in the first step! I can't re-start the program to try to catch the exceptions. What should I do? Thanks in advance for your help!

Steven Tagawa
Steven Tagawa
Python Web Development Techdegree Student 4,026 Points

You'll have to format your code so we can see how everything is indented... Your workspaces are private, so that link won't work for anyone except you.

3 Answers

Trevor J
Trevor J
Python Web Development Techdegree Student 2,078 Points

It’s because you have while tickets_remaning <= 1:.
It’s should be while tickets_remaning >= 1:

victorvillaplana
victorvillaplana
11,582 Points

Hello!

Here is my code with the right format.

Thanks!!

TICKET_PRICE = 10
tickets_remaining = 100

while tickets_remaining <= 1:   
    print("There are {} tickets remaining in this moment".format(tickets_remaining))
    user_name = input("What's your name?  ")
    number_of_tickets = input("Hello, {}, how many tickets would you like?  ".format(user_name))
    number_of_tickets = int(number_of_tickets)
    total_price = number_of_tickets * TICKET_PRICE
    print("The total due is ${}  ".format(total_price))
    confirmation = input("Do you want to proceed? (Y/N)  ")
    if confirmation.lower() == 'y':
        print("Sold!")
        tickets_remaining -= number_of_tickets
        #TODO: Gather credit card information and process it.
    else:
        print("Ups! You canceled the purchase process. Thank you anyways, {}. See you soon!!  ".format(user_name))
print("Sold out! Sorry, there are no tickets available  ")