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 trialchristopher diaz
2,364 PointsCan anyone help me understand why I cannot update the remaining tickets?
Can anyone help me understand why I cannot update the remaining tickets? It keeps outputting 100 tickets even after I input I want to purchase 100 tickets.
""" To-Do
1) As a User, I should have a personalized experience so that I feel welcomed by the brand.
2) As a User, I should have errors reported in a user-friendly manner
3) As a User, I should be able to request a certain amount of tickets and be told the total cost, so that I can determine if I want to purchase the tickets
4) As a result, I should be able to confirm my order, so that I do not accidentally purchase more tickets than intended
5)As a User, I should not be offered tickets if there aren't any available
6) As a User, I should be shown the number of tickets left remaining, so I can understand the importance of buying now. """
TICKET_PRICE = 10
ticket_remaining = 100
Run this code continuously until we run of tickets
while ticket_remaining >= 1: # Line 26 goes over the amount of tickets remaining - To-Do #6 print("There are {} tickets remaining.".format(ticket_remaining))
# Gather the user's name and assign it to a new variable - To-Do #1
CustomerName = input("Welcome to Ticket Master, lets start with your name. What is your name? ")
CustomerTicketRequest = input("Thank you {} for choosing Ticket Master, how many tickets would you like to "
"purchase? ".format(CustomerName))
CustomerTicketRequest = int(CustomerTicketRequest)
# Calculate the price (Number of tickets multiplied by the price) and assign it to a variable. Output the price -
# To-Do #3
TicketCalculation = int(CustomerTicketRequest * TICKET_PRICE)
print("Your total ticket cost is ${}".format(TicketCalculation))
# Prompt user if they want to proceed. Y/N? To-Do #4,
# If "Yes" print out a message saying "Sold!" To confirm purchase, and then decrease the amount of tickets available
# If "No" Thank them by name
CustomerConfirmation = str(input("If you would like to continue with your purchase, type 'yes' or 'no'. ")).lower()
if CustomerConfirmation != "yes":
print("Thank you for choosing Ticket Master, your purchased ticket cost is ${}".format(TicketCalculation))
ticket_remaining -= CustomerTicketRequest
else:
print("Thank you for choosing Ticket Master {}, please come again".format(CustomerName))
Notify the user that the tickets are sold out
print("Thank you for choosing Ticket Master but we are sold out.")
1 Answer
christopher diaz
2,364 PointsI resolved the issue:
if CustomerConfirmation != "yes":
I was using !=, which is meant to be used for inequalities; switching it to == (equality) works like a champ!
Mark Sebeck
Treehouse Moderator 38,006 PointsMark Sebeck
Treehouse Moderator 38,006 PointsAwesome job christopher diaz figuring it out. I select your answer as βBest Answerβ because β¦ well it is! :)