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 trialFelix Lopez
449 PointsHow much to indent and when should I? Also, keep getting a syntax error on line 10.
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >=1:
print("there are {} tickets remaining.".format(tickets_remaining))
user_name = input("what is your name? ")
num_tickets= input("Hey {}, how many tickets do you want to buy? ".format(user_name)
num_tickets = int(num_tickets)
amount_due = num_tickets * TICKET_PRICE
print("the total due is ${}") .format(amount_due))
if should_proceed.lower() =="y":
print("SOLD!")
tickets_remaining -= num_tickets
else:
print("tickets go fast, {}.").format(user_name)
print("sorry the tickets are sold out.")
2 Answers
Sumiya Malik
3,976 PointsHi I did it this way.. similar to what the instructor showed in the video lecture.
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("The number of tickets remaining: {}".format(tickets_remaining))
user_name= input("Enter your name here: ")
try:
number_of_tickets=int(input("Hi {}! How many tickets would you like ".format(user_name)))
if number_of_tickets > tickets_remaining:
raise ValueError("Only {} tickets left. Try again".format(tickets_remaining))
except ValueError as err:
print("Oh no, That is not a valid value. Try again")
print("{}".format(err))
else:
total_amount=(number_of_tickets*TICKET_PRICE)
print("Your total is ${}".format(total_amount))
answer=str.upper(input("Do you want to proceed ? (Y/N) "))
if answer==("Y"):
print("Purchase confirmed")
tickets_remaining=tickets_remaining-number_of_tickets
else:
print("{}! Thankyou for visiting our site.".format(user_name))
print("Sorry all tickets are sold!")
Maxwell Jermy
22,419 PointsI indent through using the tab button. On the Treehouse workspace it 2 spaces (shown in the bottom, left). I have just quickly mocked this up. Please follow the videos carefully, I believe you have missed things out. I hope this helps
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
# Output how many tickets are remaining using the tickets_remaining variable
print("There are {} tickets remaining.".format(tickets_remaining))
# Gather the user's name and assign it to a new variable
user_name = input("What is your name? ")
# Prompt the user by name and ask how many tickets they would like
num_tickets = input("Hey {}, how many tickets do you want to buy? ".format(user_name))
num_tickets = int(num_tickets)
# Calculate the price (number of tickets multiplied by the price) and assign it to a variable
amount_due = num_tickets * TICKET_PRICE
# Output the price to the screen
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!")
tickets_remaining -= num_tickets
else:
print("tickets go fast, {}.".format(user_name))
else:
print("sorry the tickets are sold out.")