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
Charlie Jones
1,409 PointsTry block Syntax error?
Hey Everyone!
I'm currently getting the below Sysntax error for a try block that I just cannot fix! Any ideas?
File "master.py", line 9
try:
^
SyntaxError: invalid syntax
Here is my code:
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("There are currently {} tickets remaining".format(tickets_remaining))
name = input("Welcome to Master Ticket! What is your name? ")
num_tickets = (input("Hey {}, how many tickets would you like to order? ".format(name))
try:
num_tickets = int(num_tickets)
except ValueError:
print("Oops! That wasn't a valid number. Please try again ")
else:
sub_total = num_tickets * TICKET_PRICE
print("Sub total: £{}".format(sub_total))
confirm = input("Would you like to proceed? Y/N ")
if confirm.lower() == "y":
# TODO: Gather credit card information and process it
print("SOLD!")
tickets_remaining -= num_tickets
else:
print("Thanks anyway {}".format(name))
print("I'm afraid we have now sold out!")
1 Answer
Pedro Cabral
33,586 PointsIt seems that you didn't close a parenthesis on this line:
num_tickets = (input("Hey {}, how many tickets would you like to order? ".format(name))
With that said, you don't really need that initial ( before the word input.
Charlie Jones
1,409 PointsCharlie Jones
1,409 PointsThanks Pedro! That was causing a world of pain!