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 Python Basics All Together Now Handle Exceptions

This code worked perfectly before but now it's showing SyntaxError:

TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining !=0:
    name = input("Please enter your name ")
    print("Hello and Welcome {} ".format(name))
    try:
        tickets_want = int(input("How many tickets would you like to purchase {} ".format(name)))
        if tickets_want>tickets_remaining:
            raise ValueError("Sorry only {} tickets are available".format(tickets_remaining)
    except ValueError: #showing error here!
        print("There is some problem in parsing your req, Please try again! ")
    else:
        print("Total price for the ticets is $" + str(TICKET_PRICE * tickets_want))
        print("Hurry! only {} tickets remaining".format(tickets_remaining))
        confirm = input("Do you want to confirm the purchase? Y/N ")
        if confirm == "Y" or confirm.lower() == "y":
            print("Tickets are sold")
            tickets_remaining -=tickets_want
        else:
            print("Thank you anyways")

print("All tickets SOLD" + "!" * tickets_want)

Add your code in between (at the beginning and at the end) three "" (without quotes) it's above the tab key`

Got it! I forgot a parenthesis before except but now it's not throwing ValueError, I mean it isn't showing my Message about the tickets remaining!

Found the solution, I forgot to add the as Keyword while throwing ValueError exception, actually I was writing the code by myself but when I watched the video I got the solution. Thank you though! :) Happy Coding!

i keep getting a syntaxError ,,, TICKET_PRICE = 10

tickets_remaining = 100

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) except ValuueError: print("Run into an issue. please try again") else: amount_due = num_tickets * TICKET_PRICE print("The total due is ${}".format(amount_due) should_proceed = input("Do you want to continue? Y/N ") if should_proceed.lower() == "y": # TODO: gather credit card information a process it. print("SOLD!") tickets_remaining -= num_tickets else:
print("Thank you anyways {}".format(name))
print("Sorry the tickets are all sold out!!!")

,,,

Steven Parker
Steven Parker
230,970 Points

Start a new question, and be sure to format the code.

Hint: those 3 marks should be accents, not apostrophes.

1 Answer

Steven Parker
Steven Parker
230,970 Points

Good job on resolving your issue! :+1:

But it's very hard to read unformatted Python! For future postings, please use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.