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

jordan GERMINARO
jordan GERMINARO
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))
else:
    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.