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 trial

Python Python Basics All Together Now Cleaner Code Through Refactoring

Why doesn't my service charge work?

Hi everyone!

Everything has been running smoothly until I've had to add the service charge. For some reason it just ignores it. (Don't worry, I've checked to see if my work was saved.) Where am I going wrong?

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 currently {} tickets available.".format(tickets_remaining))
    name = input("Hello, what is your name? ")
    num_tickets = input("Hey {}, how many tickets would you like? ".format(name))
    num_tickets = int(num_tickets)
    calculation = TICKET_PRICE * num_tickets
    print("Great, {} tickets will cost you".format(num_tickets), calculation, "pounds.")
    proceed = input("Would you like to proceed?\nEnter Yes or No: ")
    if proceed.lower() == 'yes':
        # TODO: Gather credit card information and process it.
        print("SOLD!")
        tickets_remaining -= num_tickets
    else:
        print("Thanks for your time {}".format(name))
print("I'm afriad the tickets have now sold out.")

1 Answer

Tyler B
Tyler B
5,787 Points

You're not actually calling your function to calculate price see line 14

calculation = TICKET_PRICE * num_tickets

should be

calculation = calculate_price(num_tickets)

Tyler, you're a genius. Thank you, I've been staring at it for over an hour now.