Python Python Basics All Together Now Handle Exceptions

walter fernandez
walter fernandez
1,386 Points

can 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
PRO
KRIS NIKOLAISEN
Pro Student 44,759 Points

Are you sure it didn't say number_tickets not defined?

tickets_remaining-= number_tickets

You previously defined this as number_of_tickets

walter fernandez
walter fernandez
1,386 Points

I 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
walter fernandez
1,386 Points

while 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))