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

Python

Nicola Loew
Nicola Loew
3,527 Points

tickets

SERVICE_CHARGE = 2 TICKET_PRICE = 10 tickets_remaining = 100

def calculate_price(num_of_tickets): return (number_of_tickets * TICKET_PRICE) + SERVICE_CHARGE

while tickets_remaining >= 1: print("There are {} tickets remaining.".format(tickets_remaining)) name = input("What is your name? ") num_tickets = input("How many tickets would you like {}? ".format(name)) try: num_tickets = int(num_tickets) if num_tickets > tickets_remaining: raise ValueError("There are only {} tickets remaining. ".format(tickets_remaining)) except ValueError as err: print("Oh no, we ran into an issue. {}. Please try again. ".format(err)) else: amount_due = calculate_price(num_tickets) print("The total due is {} ".format(amount_due)) should_proceed = input("Do you want to proceed? Y/N ") if should_proceed.lower() == "y": print("SOLD") tickets_remaining -= num_tickets else: print("Thank you anyways, {}!".format(name)) print("Sorry the tickets are all sold out!!!:(")

Nicola Loew
Nicola Loew
3,527 Points

Why am I stuck at What's your name ...How many tickets would you like? It just keeps repeating those two questions

2 Answers

youssef b10ta
PLUS
youssef b10ta
Courses Plus Student 2,755 Points
SERVICE_CHARGE = 2
TICKET_PRICE = 10
tickets_remaining = 100

def calculate_price(number_of_tickets,TICKET_PRICE):
    return (number_of_tickets * TICKET_PRICE) + SERVICE_CHARGE

while tickets_remaining >= 1:
    print("There are {} tickets remaining.".format(tickets_remaining))
    name = input("What is your name? ")
    num_tickets = input("How many tickets would you like {}? ".format(name))
    try:
        num_tickets = int(num_tickets)
        if num_tickets > tickets_remaining:
            raise ValueError("There are only {} tickets remaining. ".format(tickets_remaining))
    except ValueError as err:
        print("Oh no, we ran into an issue. {}. Please try again. ".format(err))
    else:
        amount_due = calculate_price(num_tickets,TICKET_PRICE)
        print("The total due is {} ".format(amount_due))
        should_proceed = input("Do you want to proceed? Y/N ")
        if should_proceed.lower() == "y":
            print("SOLD")
            tickets_remaining -= num_tickets
        else:
            print("Thank you anyways, {}!".format(name))
print("Sorry the tickets are all sold out!!!:")

this is your code i did fix it litte bit and now its working maybe you can see what i did change

Nicola Loew
Nicola Loew
3,527 Points

Thank Youssef Now it does work!

youssef b10ta
PLUS
youssef b10ta
Courses Plus Student 2,755 Points

maybe will be better to read your code if u use Markdown