Maximum recursion depth exceeded - 5. Pull It Together


#1



https://www.codecademy.com/courses/python-beginner-P5YtY/1/4?


Oops, try again. hotel_cost(1) raised an error: maximum recursion depth exceeded


def hotel_cost(nights):
    return 140 * hotel_cost(nights)
    
def plane_ride_cost(city):
    if city== "Charlotte":
        return 183
    elif city== "Tampa":
        return 220
    elif city== "Pittsburgh":
        return 222
    elif city== "Los Angeles":
        return 475

def rental_car_cost(days):
    cost = 40 * days
    if days >= 7:
        return cost - 50
    elif days >= 3:
        return cost - 20
    return cost

def trip_cost(city, days):
    return hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)


#2

you call the function inside the function, this causes endless function calls (sort of like an infinity loop), hotel_cost should return 140 * nights


#3

For the def trip_cost(city, days): I removed the indentation before "return hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)" and it gives an indentation error.

eg:
def trip_cost(city, days):
return hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)


#4

the problem you have is in earlier functions, not trip_cost. Don't change the indent of the trip_cost function content, do rather something about the function calls inside the functions in earlier functions (like in the hotel_cost function)


#5

Excellent, thank you for the direction! I changed the hotel_cost function to:
def hotel_cost(nights):
return 140 * nights

and then for trip_cost I indented the very last line to print days, city to include it in that function and now it works.


#6