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 trialwalter fernandez
4,992 Pointscan someone help me.
I wrote this program TICKET_PRICE = 10 tickets_remaining = 100
Output how many tickets are remaining using the tickets_remaining variable
print("There are {} tickets remaining.".format(tickets_remaining))
run this code continuosly until there is no more ticket to sell
while tickets_remaining >= 1: #Gather the user's name and assign it to a new variable name = input("what is your name?: ")
#Prompt the user names and ask how many tickets they would like
number_of_tickets = input("tell me the numer of tickets you want,{}. ".format(name))
number_of_tickets = int(number_of_tickets)
#Calculate the price (number of tickets multiplied by the price) and assign it to a variable
total_price = TICKET_PRICE * number_of_tickets
#Output the price to the screen
print(total_price)
# prompt user if they want to proceed. Y/N
ask_user = str(input('Enter yes or not if you want to proceed: '))
#If they want to proceed
if ask_user == 'yes' or 'YES' or 'Yes':
# print out to the screen "SOLD" to confirm purchase.
print('SOLD')
# and then decrement the tickets remaining by the number of tickets purchased
tickets_remaining-= number_tickets
#otherwise
else:
#Thank them by name
print('Thank {},have a nice day'.format(name))
notify the you ran out tickets.
print('tickets are Sold Out, sorry'.format(name))
the variable -- number_of_tickets is not defined. I do not know why. also, I don't know if the syntax of my if - else statement is good. thanks
3 Answers
KRIS NIKOLAISEN
54,972 PointsAre you sure it didn't say number_tickets not defined?
tickets_remaining-= number_tickets
You previously defined this as number_of_tickets
walter fernandez
4,992 PointsI tried to fix it and now say that there is invalid syntax and it seems like something is wrong with the word 'else' in my if statement.
walter fernandez
4,992 Pointswhile tickets_remaining >= 1: #Output how many tickets are remaining using the tickets_remaining variable 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 be name and ask how many tickets they would like
number_of_tickets = input("tell me the numer of tickets you want,{}. ".format(name))
number_of_tickets = int(number_of_tickets)
#Calculate the price (number of tickets multiplied by the price) and assign it to a variable
total_price = TICKET_PRICE * number_of_tickets
#Output the price to the screen
print(total_price)
# prompt user if they want to proceed. Y/N
ask_user = str(input('Enter yes or not if you want to proceed: '))
#If they want to proceed
if ask_user == 'yes' or 'YES' or 'Yes':
# print out to the screen "SOLD" to confirm purchase.
print('SOLD')
# and then decrement the tickets remaining by the number of tickets purchased
tickets_remaining -= number_tickets
#otherwise
else:
#Thank them by name
print('Thank {},have a nice day'.format(name))
notify the you ran out tickets.
print('tickets are Sold Out, sorry'.format(name))