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 trial


281 Points

Got a head scratcher for you....

ok so i wrote this code for the end project of beginer python...

import sys TICKET_PRICE = 10

tic_remain = 100
while tic_remain>0: name = input("Good Afternoon, Please Tell me your name... ") tic_buy = int(input("Hi There {}, there are only {} tickets remaining.\n How many would you like to buy?? ".format(name,tic_remain))) price = tic_buy*TICKET_PRICE

purchase = input("Awesome {} the price for {} tickets is {}.\n Would you like to buy NOW??(y/n)".format(name,tic_buy,price))
if purchase != "y":
    print("{}, Come back soon when you are ready to get your Groove on".format(name))
    if tic_buy > tic_remain:
        print (" Im sorry {} there are only {} remaining and you tried to order {} please choose {} tickets or less".format(name,tic_remain,tic_buy,tic_remain))
    if tic_buy <= tic_remain:
        print("Thank you {} your order for {} tickets in the amount of {} is being processed see you next time".format(name,tic_buy,price))
        tic_remain = tic_remain - tic_buy

print("SOLD OUT")

it works fine... BUT I want it to check if they are asking for more tickets than are still available BEFORE it asks then if they want to buy it... I tried to move the first if statement up but it didn't work does anyone have any ideas

1 Answer

You should check the Markdown Cheatsheet for information on formatting.

Since you don't show what you tried, that didn't work, we really don't know what you did wrong.