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

# I don't know where I've made the mistake but my code keeps resulting in the total being incorrect

I think I have basically the same code as Craig does in the vid but my price calculator never produces the right sum for the number of tickets. Does anybody know how to fix it? Hello, Agbo

Thank you!

Hi Justin, here is my code. I think the calculation is multiplying by the tickets remaining instead of ticket price but I'm not sure how to fix it.

```SERVICE_CHARGE = 2
TICKET_PRICE = 10

tickets_remaining = 100

def calculate_price(number_of_tickets):
return (number_of_tickets * TICKET_PRICE) + SERVICE_CHARGE

while tickets_remaining >= 1:
print("There are {} tickets remaining.".format(tickets_remaining))
name = input("What is your name?  ")
tickets_required = input("How many tickets would you like, {}?:  ".format(name))
try:
tickets_required = int(tickets_required)
if tickets_required > tickets_remaining:
raise ValueError("There are only {} tickets remaining".format(tickets_remaining))
except ValueError as err:
print("Oh no, we ran into an issue. {}. Please try again".format(err))

else:
amount_due = calculate_price(tickets_remaining)
print("The total due is £{}".format(amount_due))
confirmation = input("Would you like to proceed with your purchase? Y/N  ")
if confirmation.lower() == "y":
print("SOLD!")
tickets_remaining -= tickets_required
else:
print("Thank you for visiting our website {}!".format(name))
print("Sorry we are all sold out! :(")
``` ```SERVICE_CHARGE = 2
TICKET_PRICE = 10

tickets_remaining = 100

def calculate_price(number_of_tickets):
return (number_of_tickets * TICKET_PRICE) + SERVICE_CHARGE

while tickets_remaining >= 1:
print("There are {} tickets remaining.".format(tickets_remaining))
name = input("What is your name?  ")
tickets_required = input("How many tickets would you like, {}?:  ".format(name))
try:
tickets_required = int(tickets_required)
if tickets_required > tickets_remaining:
raise ValueError("There are only {} tickets remaining".format(tickets_remaining))
except ValueError as err:
print("Oh no, we ran into an issue. {}. Please try again".format(err))

else:
amount_due = calculate_price(tickets_required) # ======>  CORRECT VARIABLE: tickets_required
print("The total due is £{}".format(amount_due))
confirmation = input("Would you like to proceed with your purchase? Y/N  ")
if confirmation.lower() == "y":
print("SOLD!")
tickets_remaining -= tickets_required
else:
print("Thank you for visiting our website {}!".format(name))
print("Sorry we are all sold out! :(")
```

Thank you Patricia! I realised where I went wrong as I was writing my question 🤦🏾‍♂️