Python Python Basics All Together Now Handle Exceptions

Mike Moore
Mike Moore
529 Points

Im getting a SyntaxError on line 6. Any suggestions?

TICKET_PRICE = 10 tickets_remaining = 100

while tickets_remaining != 0:
print("There are {} tickets remaining".format(tickets_remaining)
name = input("Enter your name? ")
number_of_tickets = input("{} How many tickets would you like?".format(name))

try:
    number_of_tickets = int(number_of_tickets)
except ValueError:
    print("You must enter a number")
else: 
    total_price = number_of_tickets * TICKET_PRICE
    print("{} the total cost of your tickets will be £{}".format(name,total_price))
    proceed = input("{} would you like to proceed please answer Y/N".format(name))

    if proceed == "Y":
        print("Sold!")
        tickets_remaining = tickets_remaining - number_of_tickets
    else: 
        print("Thanks {}".format(name))

print("Sorry, there are no more tickets availabe")

Mike Moore
Mike Moore
529 Points

Never mind, I realised I missed a parenthesis at then died of line 5, it works now

1 Answer

Steven Parker
Steven Parker
194,962 Points

Spelling, indentation, and balanced parentheses are always good "first glance" checks for errors.

And when posting code to the forum, use Markdown formatting to preserve the appearance, or share the entire workspace by making a snapshot and posting the link to it.