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 trialFrancis Neal
528 PointsI'm getting a syntax error at the else statement at the end of the script, but don't know what it is
Hi All,
I don't know why I'm getting the syntax error. I'm following along in the python basics course, the masterticket script in the section "fitting it altogether"
TICKET_PRICE = 10 tickets_remaining = 100
Output how many tickets are remaining using the tickets remaining variable
""" tickets_remaining = tickets_remaining -= 1 """ print("There are {} tickets remaining.".format(tickets_remaining))
Gather the users name and assign it to a new vareiable
users_name = input("Choose a user name: ")
Prompt the user by name and ask how many tickets they would like
number_of_tickets = int(input("{} how many tickets would you like? ".format(users_name)))
Calculate the price (number of tickets multiplied by the price) & assign it to a variable
price = number_of_tickets * TICKET_PRICE
Output the price to the screen
print("The cost of your tickets is {}".format(price))
Prompt the user if they want to proceed. Y/N
proceed = input("Do you want to proceed? Y/N ")
If they want to proceed
if proceed == "Y": print("SOLD")# Print out to the screen "SOLD!" to confirm purchase tickets_remaining = tickets_remaining - number_of_tickets # and the decrement the tickets remaining by the number of tickets purchased print("There are only {} tickets left".format(tickets_remaining)) else: print("Thanks for looking {}".format(users_name))
""" elif proceed == "N": # Otherwise / else print("There are still {} tickets left. Thanks for looking {}".format(tickets_remaining, users_name)) # Thank them by name
elif proceed gives a syntax error at the elif?? else is also giving me a syntax error!!!
"""
Steven Parker
231,275 PointsUse the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area.
Or watch this video on code formatting.
1 Answer
Steven Parker
231,275 PointsIf the "elif" line were outside of the comments it would cause an error because a plain "else" must come last in a chain of "if ... elif ... else".
Without formatting, it's not clear what other issues may exist. The code could operate as-is if the indentation is correct.
Alex Koumparos
Python Development Techdegree Student 36,887 PointsAlex Koumparos
Python Development Techdegree Student 36,887 PointsHI Francis, In order to help you, please ensure that you follow the Markdown Cheatsheet for properly formatting your code.
This is always important for readability, but especially so for languages like Python where whitespace is significant.
There is a link to the Cheatsheet at the bottom of every question field and you can use the preview button in the bottom right corner of every question field to make sure your post looks the way you think it does.
Thanks
Alex