
Radoslaw Skalski
374 PointsTicket Remaining problem
Hi,
Im completely stuck in one place:
console showing "There are tickets_remaining tickets remaining. "
I can
t find any issue of that,
here is a code
TICKET_PRICE = 10
tickets_remaining = 100
while tickets_remaining >= 1:
print("There are {} tickets remaining.".format("tickets_remaining"))
name = input("What is your name? ")
num_tickets = input("Ammount of tickets {}? ".format(name))
try:
num_tickets = int(num_tickets)
if num_tickets > tickets_remaining:
raise ValueError("There are only {} tickets left".format(tickets_remaining))
except ValueError as err:
print("Wrong value.{} Try again".format(err))
else:
ammount_due = num_tickets * TICKET_PRICE
print("Total price is {}$".format(ammount_due))
proceed = input("Would you like proceed? Y/N")
if proceed.lower() == "y" :
print("SOLD!")
tickets_remaining -= num_tickets
else:
print("thanks anyway!",format(name))
print("Sorry all Sold")
2 Answers

Steven Parker
177,538 PointsThe cause is this line:
print("There are {} tickets remaining.".format("tickets_remaining"))
Because of the quotes around "tickets_remaining", it is taken as a literal string and used to replace the token (the "{}") in the original string.
If you want to display the value of the varible named tickets_remaining
, don't put quotes around it.

Radoslaw Skalski
374 Pointsthanks a lot!