0
def aquariumTicket(total = 0):
    age = input("What is your age?")
    if age < 3:
        price = 0
    elif age >=3 and age <=12:
        price = 19.5
    elif age >= 55:
        price = 21.5
    elif age >12 and age <55:
        price = 26
    print "Ticket price: $%.2f" % price
    others = raw_input("Anyone else? (y/n)")
    if others == "y":
        return aquariumTicket(total)
    else:
        print "Total price: $%.2f" % price

i have everything working except i don't know how to code for the last part of the function to calculate the total price of all the people. help please?

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by slate
0

Total price would be a separate variable that you add price to. If you want to process more than one person at a time and give a grand total, there would have to be a while loop somewhere in the program.

0

As woooee said you should maintain a total price between the age inputs, and print it as the total price.

def aquariumTicket(total = 0):
    age = input("What is your age?")
    if age < 3:
        price = 0
    elif age >=3 and age <=12:
        price = 19.5
    elif age >= 55:
        price = 21.5
    elif age >12 and age <55:
        price = 26
    print "Ticket price: $%.2f" % price
    total+=price
    others = raw_input("Anyone else? (y/n)")
    if others == "y":
        return aquariumTicket(total)
    else:
        print "Total price: $%.2f" % total
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.