[Python] Why does it say that I have reached the max recursion depth? How can I fix it?

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    cities = ["Boston", "Las Vegas", "Porto Alegre", "Cape Town", "Berlin", "Okinawa", "Sydney"]
    hotels = [255, 450, 150, 250, 650, 675, 850]
    flights = [950, 3000, 4500, 2750, 2500, 3500, 10500]


    def add_destination(city, hotel, flight):
    global cities, flights, hotels
    print("""Add your desired destination. Please include your hotel and flight cost,
    as well as the name of your desired location and hotel.""")
    new_place_city = input("Please type your new city: ")
    new_place_hotel = int(input("Please type your new hotel's price per night: "))
    new_place_flight = int(input("Please type the cost of your flight:"))
    cities.append(new_place_city)
    hotels.append(new_place_hotel)
    flights.append(new_place_flight)

    cost = [flights] + [hotels]

    def calculate_total_cost(hotels, flights):
    global city, hotel, flight, cost
    f_cost = sum(flights)
    h_cost = sum(hotels)
    t_cost = sum({h_cost, f_cost})
    result = calculate_total_cost(hotels, flights)




    def display_budget_summary(cities, hotels, flights):
    for i in range(len(cities)):
    print(f"{cities}, ${hotels} ${flights}.")
    result = calculate_total_cost(hotels, flights)
    print(f"Your current budget/money spent is ${result}.")

    while True:
    print(f"""Currently, the cities you plan to visit during your vacation are {cities}."
    Please choose an option to make any edits to your vacation.""")
    print("1. Add a destination")
    print("2. View budget summary")
    print("3. Exit program")

    option = int(input("Please choose an answer: "))

    if option == 1:
    add_destination(cities, hotels, flights)

    elif option == 2:
    display_budget_summary(cities, hotels, flights)

    elif option == 3:
    break

    else:
    print("Please choose a valid option.")


    Provided above is my code. When I run this on Online Python, I receive the error message that I have reached the maximum recursion distance, and I am confused as to what I can due to fix this. From what I understand, most of the issues lie around the display function. Can anyone elaborate as to how I can fix this mistake?

    Continue reading...

Compartilhe esta Página