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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Enes artun](https://secure.gravatar.com/avatar/ef0c37a749a1ab506bf97fba7e94c0ce?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Enes artun
Courses Plus Student 2,364 PointsStuck in a loop.
Hi. My script for some reason seem to be stuck in a loop. I tried to add break to the end of it but I got break outside loop error. What can I do to fix it?
I ask for 56 tickets first. Receive 44 ticket left. During the second run I ask for 44 tickets but get 56 tickets left instead.
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
name = input('What is your name? ')
print(f'Welcome {name}')
buy_tickets = int(input(f'How many tickets do you want {name}? '))
total_cost = buy_tickets * TICKET_PRICE
print(f'Total cost is {total_cost} $')
ask = input('Would you like to proceed? Y/N ')
if ask.lower() == 'y':
print(f'Order received. {buy_tickets} ticket reserved.')
r_tickets = tickets_remaining - buy_tickets
print(f'{r_tickets} tickets left.')
else:
print(f'Thank you for considering us {name}.')
print('Sorry the tickets are all sold out.')
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsThe "tickets_remaining" is not being updated in this code, so every transaction will draw from the original 100.
So instead of creating a new total like this:
r_tickets = tickets_remaining - buy_tickets
print(f'{r_tickets} tickets left.')
You could update the count of remaining tickets instead:
tickets_remaining -= buy_tickets
print(f'{tickets_remaining} tickets left.')