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

Hey there my code keep looping even after printing out (SOLD and remaining tickets )?

Fro some reason even after its prints out SOLD and remaining tickets its keep looping all over again like "Name input". I think my indentation is wrong.


tickets_remaining = 100

while tickets_remaining:

print("There are {} tickets ramaining.".format(tickets_remaining))
name = input("What is your name: ")
num_tickets = input("How many tickets would you like , {}? ".format(name))
num_tickets = int(num_tickets)
amount_due = num_tickets * TICKET_PRICE
print("Total due is ${}".format(amount_due))

proceed = input("Would you like to proceed, Y/N {}?".format(name))
if proceed == "Y" or "y":
  tickets_remaining -= num_tickets
  print("Thank you anyways {}!".format(name))

print("Sorry the tickets sold out!!!")

While loops lack of condition: while tickets_remaining >= 1:

You should add a condition to the while loop

#Run this code until we run out of tickets
while tickets_remaining >= 1:

Although you are looking at it being true being more expanding on that will be better for the future.

1 Answer