Help with summing up all ticket prices

I need help figuring out how to output all ticket prices out using a counter please help

e question and answer! :slight_smile:

def ticket_price(miles): if miles >= 30: price = 12 elif miles>= 29 or miles>= 20: price =10 elif miles >= 19 or miles >= 10: price = 8 else: price = 5 return miles all_ticket_prices = 0 response = input("Do you want to start this program (yes or no) ") while response == "yes": last_name = input("Please enter your last name ") miles = float(input("How many miles are you away from downtown chicago ")) response = input("Do you want to start this program (yes or no) ") all_ticket_prices = all_ticket_prices + price price = ticket_price(miles) all_ticket_prices = all_ticket_prices + price print("This is your ticket price", price) print("All price ticekts", all_ticket_prices)

Prices are not printed because:

  1. You have a unresolved reference of price on line 19. That means the variable was not properly declared.
  2. The ticket_price method was constructed incorrectly. It was returning miles, not price.
    You actually declared price after this line.
  3. You had an extra input method on line 18 that you do not need. The following code should work as intended:
def ticket_price(miles):
    price = 0
    if miles >= 30:
        price = 12
    elif miles >= 29 or miles >= 20:
        price = 10
    elif miles >= 19 or miles >= 10:
        price = 8
    else:
        price = 5
    return price


all_ticket_prices = 0

while True:
    response = input("Do you want to start this program (yes or no) ")
    if response == 'no':
        print('Goodbye!')
        break
    last_name = input("Please enter your last name ")
    miles = float(input("How many miles are you away from downtown chicago "))
    price = ticket_price(miles)
    all_ticket_prices = all_ticket_prices + price

    print("This is your ticket price", price)
    print("All price ticekts", all_ticket_prices)

Screenshot

image

Let me know if this resolve your issue or if you need further assistance.