Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

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.

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