Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics All Together Now Branch and Loop

tickets_remaining is always 100

each time i run the code the tickets_remaining is always 100

Steven Parker
Steven Parker
210,423 Points

Please 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.

4 Answers

Jose Javier Garcia-Rovira
Jose Javier Garcia-Rovira
3,986 Points

Hi Tinotenda,

Can you share your code so that I can review it and help you find the issue?

Cheers!

Maba Bah
Maba Bah
2,744 Points

TICKET_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!")

Can we see your code

Dom Ss
Dom Ss
4,338 Points

Here 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.