Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics All Together Now Branch and Loop

MY code is working fine but when I input 95 tickets and then run the loop again and input 5 tickets the loop doesn't end


tickets_remaining = 100  

#continuous loop to check for tickets remaining

while tickets_remaining >= 1:

# Output how many tickets are remaining using the ticket_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 
  ask = int(input("Hi {} how many tickets would you like ? ".format(name)))

  # calculate the price and quantity of the tickets
  total_price_quantity = TICKET_PRICE * ask

  #output the total
  print("The total will be £{}".format(total_price_quantity))

  # Prompt user if they want to proceed Y/N?
  proceed = input("Do you want to continue with Purchase ? " + ("Y/N "))

  #if they want to proceed
  #print out to the screen ~sold! to comfirm purchase
  if proceed.lower() == "y":
    remain_tickets = tickets_remaining - ask
    #decrement the tickets remaining by the number of tickets purchased
    print("Sold!! " + "There are {}".format(remain_tickets) + " Tickets remaining")
  #Thank them by name
    print("Thank you {}".format(name))

  #Notify user that the tickets are sold out  
    print("Tickets are sold out!!")

Mod Edit: Fixed code formatting. See Steven Parker's answer below for the best ways to include your code.

1 Answer

Steven Parker
Steven Parker
210,424 Points

The loop runs based on the value of "tickets_remaining", but the updated number of tickets is being stored in "remain_tickets". After a sale, you should see ""There are 100 tickets remaining" as evidence that the loop value has not been changed.

For future questions, always use use Markdown formatting to preserve the code's appearance and retain special symbols. An even better way to share code and make your issue easy to replicate is to make a snapshot of your workspace and post the link to it here.