Python Python Basics All Together Now Handle Exceptions

Michael Quiban
Michael Quiban
2,388 Points

Invalid Syntax on subtraction equal assignment operator on tickets_remaining?

So my issue is with tickets_remaining -=

When I attempt to subtract the purchased tickets from my overall amount of tickets, it gives me an invalid syntax error at:

treehouse:~/workspace$ python
File "", line 27
tickets_remaining -= tickets
SyntaxError: invalid syntax

Anyone know a way around this?

3 Answers

54,333 Points

If you want to share your workspace take a snapshot. It's the camera icon in the upper right corner.

Your syntax error is not on the line given but on the line before this:

print("SOLD! Thanks for confirming your purchase of {} ticket's".format(tickets) 

here you are missing the closing parenthesis of your print statement

print("SOLD! Thanks for confirming your purchase of {} ticket's".format(tickets)) 

You should review your use of parentheses in all of your print statements. There are a few where the parentheses are missing/in the wrong place.

You also have a variable 'should_proceed' but then check a variable 'proceed'. I made changes to these and others in the provided snapshot.

Michael Quiban
Michael Quiban
2,388 Points

Awesome Kris, I really appreciate your help.

I've revised your changes and will definitely pay more closer attention.

Closing and +1

Hi!, your link is broken can u post again?

HI!, it saying page not found. can u format ur code in here?

you use 3 ```(pythpn)

<your code goes here>

and then 3 ```

Michael Quiban
Michael Quiban
2,388 Points

tickets_remaining = 100

# Run this code until tickets are gone

# Output how many tickets are remaining using the tickets_remaining variable
print("There are  {} tickets remaining.".format(tickets_remaining))

# Gather user 's name and assign it to a new variable
name = input("What's your name? ")

# prompt the user and ask how many tickets they 'd like
tickets = input("Hey {}! How many tickets would you like? ".format(name))
tickets = int(tickets)

# Calculate the price(Number of tickets multiplied by Ticket_Price)
ticket_sale = tickets * TICKET_PRICE

# Output the price to the screen
total = print("Your total will be ${}.00, enjoy the park!".format(ticket_sale))

# Prompt user if they want to proceed
should_proceed = input("Would you like to continue? (Y/N)? ")# If they want to proceed
if proceed.lower() == "y": #print out ot the screen "SOLD!"to confirm purchase
    print("SOLD! Thanks for confirming your purchase of {} ticket's".format(tickets) 
          tickets_remaining -= tickets 
          print("We now have {} ticket's remaining!").format(tickets_remaining)

    # and then decrement the tickets remaining by the number of tickets purchased 
    elif proceed == "N":
        print("That's unfortunate, here's your total of ${}.00 back").format(ticket_sale)

    # otherwise thank the user for using this application.
         print("Thanks for interacting with this application, {}").format(name)