Python Python Basics All Together Now Handle Exceptions

Masterticket.py - can't decrease ticket sells

Assignment is to decrease ticket sells until no tickets are available. I thought I followed the video but apparently I didn't. Sold and decreasing tickets do not print or work.

Here's my code, what is wrong?

TICKET_PRICE = 10

tickets_remaining = 100

while tickets_remaining >= 1: print("There are {} tickets remaining.".format(tickets_remaining)) first_name = input("What is your first name? ") tickets_requested = input("How many tickets would you like, {}? ".format(first_name)) tickets_requested = int(tickets_requested) amount_due = tickets_requested * TICKET_PRICE print("The total due is ${}".format(amount_due)) proceed = input("Would you like to purchase the tickets? Y/N ") if proceed.lower() == "y": # TODO: Gather credit card information and process it.
print("SOLD!") tickets_remaining -= tickets_requested else: print("Thank you for your interest, {}!".format(first_name)) print("Sorry the tickets are all sold out!")

4 Answers

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,172 Points

You should format your code using markdown. See the cheatsheet at the bottom of the page. This is especially true for Python where indentation is very important.

Here is a snapshot of your code that appears to function correctly:

https://w.trhou.se/rlnx348dwe

Do you see errors in the console when you run yours?

Kris, there are no errors showing in console except it continues to state I have 100 tickets available. It doesn't matter whether one person buys all 100 or I split it up amongst other purchasers. It doesn't print out ("SOLD"!) or anything it just keeps asking me what is my name and how many tickets I wish to purchase.

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,172 Points

It sounds like your if proceed.lower() == "y": block isn't indented enough. Can you post a snapshot? It is the camera icon in the upper right corner of the workspace.

Kris, It was my indenting.

TICKET_PRICE = 10

tickets_remaining = 100

while tickets_remaining >= 1: print("There are {} tickets remaining.".format(tickets_remaining)) first_name = input("What is your first name? ") tickets_requested = input("How many tickets would you like, {}? ".format(first_name)) tickets_requested = int(tickets_requested) amount_due = tickets_requested * TICKET_PRICE print("The total due is ${}".format(amount_due)) proceed = input("Would you like to purchase the tickets? Y/N ") if proceed.lower() == "y": # TODO: Gather credit card information and process it.
print("SOLD!") tickets_remaining -= tickets_requested else: print("Thank you for your interest, {}!".format(first_name)) print("Sorry the tickets are all sold out!")

The print line for the if proceed.lower command was not indented properly.

Thanks for you assistance.