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 trialpriyanka shukla
3,051 Pointsproblem 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
2,476 PointsRefer 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.