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

Python

Kenneth Huddleston
Kenneth Huddleston
1,494 Points

Trouble with Python code...

The below code is giving me a syntax error at line 30. I can't seem to figure out why... Does anyone have any ideas?

import sys as s

TICKET_PRICE = 10

tickets_remaining = 100

# output how many tickets remaining

print("There are {} tickets remaining".format(tickets_remaining))

# Gather the user's name and assign it to a new variable.

name = input("What is your name?  ")

# Prompt the user by name and ask how many tickets they would like to purchase
# Calculate the price (number of tickets multiplied by the price)
# Output the price to the screen

number_of_tickets = int(input("Hello, {}! How many tickets would you like to purchase today?  ".format(name)))
total_cost = float(TICKET_PRICE * number_of_tickets)
print("The total price is ${}".format(total_cost))

# Prompt user if they want to proceed. Y/N

print("The number of tickets you are buying is {} for a total of ${}.".format(number_of_tickets, total_cost))
confirmation = input("Would you like to proceed? (Y/N)?  ")

# If they want to proceed, print out "SOLD!" to the screen to confirm purchase. Also, reduce ticket count by number of tickets bought.

if confirmation.upper is == "Y" or confirmation.upper is == "YES":
    tickets_remaining -= number_of_tickets
    print("SOLD! Enjoy the concert, {}".format(name))    

# If they do not want to proceed, thank them by name.
else:
    print("Thank you for your interest, {}. I hope you have a wonderful day!".format(name))
    s.exit()

1 Answer

while tickets_remaining >= 1: # want to output the remaining ticket using tickets_remaining

print("There are {} tickets left!".format(tickets_remaining))


# We would need to find out their name and make it into a variable

name = input("Hi there! Welcome to MasterTicket! Whats your name?   ")

# Prompt the user by name and ask them how many tickets they would like
number_of_tickets = input("Hi {}! How many tickets would you like to purchase?  ".format(name)) 

number_of_tickets = int(number_of_tickets)

# Calculate the price (number of tickets * ticket price) assign to variable

total_due = number_of_tickets * TICKET_PRICE

# Output the price to the screen

print("Your total will be ${}!".format(total_due))

# Prompt user is the want to proceed? y/n
proceed_out = input("Would you like to proceed? Y/N ")

# If they want to proceed 
if proceed_out.lower() == "Y" :
# print out to the screen "sold!"
#TODO: Gather credit card info
    print("Sold!")
# reduce tickets remaining by the number purchased
    tickets_remaining -= number_of_tickets
    print("There are {} tickets remaining!".format(tickets_remaining))

# otherwise.....
else:
    print("Thank you for stopping by {}!".format(name))
# Thank them by name

# Notify User that tickets are sold out  

print("Sorry! We are sold out!")

I believe this should point out whats wrong Kenneth Huddleston

Kenneth Huddleston
Kenneth Huddleston
1,494 Points

I appreciate you sharing your code! I hate to be difficult, but I still don't see the issue. Mine seems roughly comparable, and I don't see any punctuation or indentation errors...

Kenneth Huddleston
Kenneth Huddleston
1,494 Points

Ah. Never mind. I figured it out. It was an unnecessary 'is' statement on line 30 that was doing me in. Thanks for the help, Christian! Your code was a real life-saver.