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,768 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.