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 trial

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

TICKET_PRICE = 10

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")
    #otherwise
  #Thank them by name
  else:
    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
231,275 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.