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
arielp
3,516 Pointswhat is wrong with my code?
TICKET_PRICE = 10
tickets_remaining = 100
run this code continuously until we run out of tickets
while tickets_remaining >= 1: # output how many tickets remaining using the tickets_remaining variable print("There are {} tickets ramaining".format(tickets_remaining)) # gather the user's name and assing it to a new variable user_name = input("What is your name?: ")
#prompt the user by name and ask how many tickets they would like
tickets_required = input("How many tickets would you like,{}? ".format(user_name))
# Expect a ValueError(handle it appropriately )test it!
try:
tickets_required = int(tickets_required)
if tickets_required > tickets_remaining:
raise ValueError("tickets available {} try again".format(tickets_remaining)
except ValueError as err:
print("that's not a valid entry please {} try again".format(err))
else:
#calculate the price(number if tickets * price)and assing it to a variable
total_sale = tickets_required * TICKET_PRICE
#output the price to the screen
print("the grand total is {} ".format(total_sale))
#prompt the user is they want to proceed. Y/N?
proceed = input("Do you want to continue Y/N?")
#confirm purchase
#TODO gather card payment details
if proceed.lower() == "y":
print("SOLD! Thank you for your Purchase!")
#displays the remaining amount of ticket available for next sale
tickets_remaining -= tickets_required
else:
print("Thanks you anyway {}".format(user_name))
notify the user that the tickets are sold out
else:
#notify the user that the tickets are sold out
print("Sorry tickets are sold out")
File "master_ticket2.py", line 20
except ValueError as err:
^
SyntaxError: invalid syntax
WHY IS COMPLAINING ABOUT EXCEPT IN LINE 20 ???
I can't figure out..
thanks
3 Answers
arielp
3,516 Pointswow, sorry guys no idea why the text of my question looks like that, a newbie here :|
arielp
3,516 Pointsooohhh yes off curse! many thanks! ....also thanks for the extra tips!
Tom Watson
9,987 PointsHey Ariel,
You're missing a closing parenthesis on line 7:
raise ValueError("tickets available {} try again".format(tickets_remaining)
Once that's fixed the script is throwing a NameError but i'll let you figure it out ;)
Also, check out the Markdown Cheatsheet when formatting your posts.
Nathan English
Front End Web Development Techdegree Student 10,817 PointsNathan English
Front End Web Development Techdegree Student 10,817 PointsMake sure to put the language in front of the first set of tilda keys "```python
"```