Python Python Basics All Together Now Branch and Loop

problem in ticket_remaining:

ticket purchasing app

TICKET_PRICE=10; ticket_remaining=100;

while ticket_remaining>0 :

print(" there are {} tickets left to purchase ".format(ticket_remaining))
# Gather a user name and assign it to variable

usr_name=input("please tell your name ? ")

#prompt the user name and ask how many tickets they want

no_of_tickets=int(input("Hi {} !! \nplease tell how many tickets you want : ".format(usr_name)))

#calc price

def get_total_price(n_tickets) :
    return n_tickets*TICKET_PRICE
print("your total due is: {} rs ".format(get_total_price(no_of_tickets)))

cnf_ticket=input("sure to proceed please respond by entering \ny or n for yes or no: ")
if cnf_ticket.lower()=='y' :
    print ("Sold out!!")
    ticket_remaining-=no_of_tickets
else :
    print(" thanks anyway {}".format(usr_name))

notify user that the tickets are sold out

print("All tickets are sold out\n please come again")

my problem is that if i put more then 100 value in first time it shows all tickets are sold but according to me it should generate an error because user asked for value which is greater then total no tickets... again thanks for reading sorry for writting code poorly just a begineer

1 Answer

Gabriel Rumbaut
Gabriel Rumbaut
2,472 Points

Refer back to the video on exceptions. If you want to do this, you'll need to raise an exception to handle it. Alternatively, you can probably do it as an if/else block somewhere in your code.