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 trialAizah Sadiq
2,435 PointsI can't figure out why I'm getting an invalid syntax
5 Answers
Steven Parker
231,172 PointsWithout using Markdown formatting, it's difficult to be sure, but it looks like there may be some indentation issues in this code. The indentation amount per level doesn't seem to be consistently implemented.
Review your indentation, make sure what ever amount you choose for a level is implemented consistently throughout the entire file, and be sure each line is indented to the correct stop for what it is indented to do.
If you still have trouble, repost the code using the formatting as explained in the video I linked to above.
Aizah Sadiq
2,435 Points'''python
TICKET_PRICE = 10
tickets_remaining = 100 while tickets_remaining >= 1:
print("There are {} tickets remaining".format(tickets_remaining))
name = input("What is your name? ")
# Expect a ValueError to happen and handle it appropriately
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 {} remaining".format(tickets_remaining))
except ValueError as err:
print("Oh no, we ran into an issue try again")
# include the error text in the output
print("Oh no we ran into an issue. {} Please try again.".format(err)
amount_due = num_tickets * TICKET_PRICE
else:
print("The total amount due is ${} ".format(amount_due))
should_proceed = input("Would you like to proceed \n (Enter Y or N) ")
if should_proceed.lower() == "y":
# gather credit card information and process it
print("SOLD!")
tickets_remaining -= num_tickets
else:
print("thank you anyway,{}!".format(name))
print("Sorry the tickets are all sold out!:(") '''
Steven Parker
231,172 PointsThose 3 marks should be accents, not apostrophes. And you can edit the original question to fix the formatting, you don't need to post again as an "answer'.
``` these, not these '''
Aizah Sadiq
2,435 Pointsthank you
Aizah Sadiq
2,435 PointsTICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("There are {} tickets remaining".format(tickets_remaining))
name = input("What is your name? ")
# Expect a ValueError to happen and handle it appropriately
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 {} remaining".format(tickets_remaining))
except ValueError as err:
# include the error text in the output
print("Oh no we ran into an issue. {} Please try again.".format(err)
else:
amount_due = num_tickets * TICKET_PRICE
print("The total amount due is ${} ".format(amount_due))
should_proceed = input("Would you like to proceed \n (Enter Y or N) ")
if should_proceed.lower() == "y":
# gather credit card information and process it
s print("SOLD!")
tickets_remaining -= num_tickets
else:
print("thank you anyway,{}!".format(name))
print("Sorry the tickets are all sold out!:(")
Hi I'm still receiving an error ```python
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("There are {} tickets remaining".format(tickets_remaining))
name = input("What is your name? ")
# Expect a ValueError to happen and handle it appropriately
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 {} remaining".format(tickets_remaining))
except ValueError as err:
include the error text in the output
print("Oh no we ran into an issue. {} Please try again.".format(err)
else:
amount_due = num_tickets * TICKET_PRICE
print("The total amount due is ${} ".format(amount_due))
should_proceed = input("Would you like to proceed \n (Enter Y or N) ")
if should_proceed.lower() == "y":
gather credit card information and process it
s print("SOLD!")
tickets_remaining -= num_tickets
else:
print("thank you anyway,{}!".format(name))
print("Sorry the tickets are all sold out!:(")
```python
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("There are {} tickets remaining".format(tickets_remaining))
name = input("What is your name? ")
# Expect a ValueError to happen and handle it appropriately
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 {} remaining".format(tickets_remaining))
except ValueError as err:
# include the error text in the output
print("Oh no we ran into an issue. {} Please try again.".format(err)
else:
amount_due = num_tickets * TICKET_PRICE
print("The total amount due is ${} ".format(amount_due))
should_proceed = input("Would you like to proceed \n (Enter Y or N) ")
if should_proceed.lower() == "y":
# gather credit card information and process it
s print("SOLD!")
tickets_remaining -= num_tickets
else:
print("thank you anyway,{}!".format(name))
print("Sorry the tickets are all sold out!:(")
Im receiving an invalid syntax this is the exact error File "masterticket.py", line 20
else:
^
SyntaxError: invalid syntax
Aizah Sadiq
2,435 PointsHi, sorry to bother you again, but I still seem to be getting the same invalid syntax as before, I have updated my question with my current code
Steven Parker
231,172 PointsI added another update to my answer.
Steven Parker
231,172 PointsSteven Parker
231,172 PointsUPDATE: there are still a number of syntax/indentation issues, for example:
s print("SOLD!")
", but the "s" is not a Python keywordAnd that "```python" sequence to start a code block must be on a line by itself. But an even better way to share code is to make a snapshot of your workspace and post the link to it here. It takes very little space in the question but it shares all the code with no formatting issues.
Steven Parker
231,172 PointsSteven Parker
231,172 PointsANOTHER UPDATE — in the new code, these issues stand out: