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 trialTinotenda Emmanuel Nyamukapa
5,127 Pointstickets_remaining is always 100
each time i run the code the tickets_remaining is always 100
4 Answers
Jose Javier Garcia-Rovira
3,986 PointsHi Tinotenda,
Can you share your code so that I can review it and help you find the issue?
Cheers!
Maba Bah
2,744 PointsTICKET_PRICE = 10 tickets_remaining = 100
Keep runnin code so long as there are tickets for sale
while tickets_remaining >= 1:
Output how many tickets are remaining using the tickets_remaining variable
print("There are only {} tickets left!".format(tickets_remaining))
#Gather the user's name and assign it to a new variable
username = input("Hello! what is your name? ")
#Prompt the user by name and ask how many tickets they would like.
tickets_requested = int(input("Hey {}, How many tickets would you like to purchase? ".format(username)))
#Calcualte the price and assign it to a variable,
total = tickets_requested * TICKET_PRICE
# Output the price to screen
print("Your total {} is ${}".format(username,total))
#Prompt user if they want to proceed Y/N
#If they want to proceed
#print out to screen SOLD!
#and then decrement the tickets remaining
Y = "Y"
N = "N"
confirm = input("Would you like to proceed? ")
if confirm == Y:
print("SOLD!")
tickets_remaining -= tickets_requested
else: print("Thank you {}, Have a nice day!".format(username))
print("Tickets are SOLD OUT!")
Favour Uche
3,551 PointsCan we see your code
Dantee Fluellen
1,499 Pointshere is you answer https://w.trhou.se/oyka72xeit click help.py line 30
Dom Ss
4,339 PointsHere is mine Workspace: https://w.trhou.se/doz1vwq3eh
What I fail to understand is the global scope to local scope. How do I update the variable remaining_tickets. I was thinking that I should just return from my function remaining_tickets, but that did not work.
Steven Parker
231,268 PointsSteven Parker
231,268 PointsPlease post your code (with Markdown formatting); or even better, make a snapshot of your workspace and post the link to it here. Then we can take a look and help figure it out.