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

Mariana Lashta
PLUS
Mariana Lashta
Courses Plus Student 4,251 Points

When I use While My program runs forever , even I gave A CONDITION (while ticket_remaining>=1:)

ticket_price=10 ticket_remaining=100 while ticket_remaining>=1: print("There are {} ticets rem. ".format(ticket_remaining)) name=input("What is your name? ") num_tickets=int(input("How many tick would ou like {} ? ".format(name))) amount_due=num_tickets*ticket_price print("The total due is {} $ ! ".format(amount_due)) should_proceed=input("Do you want to proceed? Y/N") if should_proceed.lower() =="y": print("SOLD!") ticket_remaining-=num_tickets else: print("Thank you anyways {}! ".format(name)) break if ticket_remaining==0: print("sorry ticket are all sold out")

My program run forever? Why is that?

Steven Parker
Steven Parker
230,970 Points

Your program might have an indentation error, but it's impossible to check that in unformatted code.

Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:
Or watch this video on code formatting.

1 Answer

Andrei Saranut
Andrei Saranut
768 Points
ticket_price = 10 
ticket_remaining = 100 
while ticket_remaining >= 1 : 
      print("There are {} ticets rem. ".format(ticket_remaining)) 
      name = input("What is your name? ") 
      num_tickets = int(input("How many tick would ou like {} ? ".format(name))) 
      amount_due = num_tickets*ticket_price 
      print("The total due is {} $ ! ".format(amount_due)) 
      should_proceed = input("Do you want to proceed? Y/N") 
      if should_proceed.lower() == "y" : 
            print("SOLD!") 
            ticket_remaining -= num_tickets 
      else: 
            print("Thank you anyways {}! ".format(name)) 
      if ticket_remaining == 0: 
            print("sorry ticket are all sold out")

try without brake and make sure the spaces are properly set