Taking a Vacation


#1




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


im not sure what ive done wrong


def hotel_cost(nights):
    return hotel_cost(140 * 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 rental_car_cost(days)+hotel_cost(days)+plane_ride_cost(city)


#2

Hi, @corerunner16726 ,

You have this inside the hotel_cost function ...

return hotel_cost(140 * nights)

That is an example of recursion, whereby a function calls itself. Sometimes, that is a valid strategy, but it would need to be performed in a manner that prevents the recursion from occurring indefinitely.

In this particular case, do you need to have the function call itself?


#5

A post was split to a new topic: Taking a vacation


#6

A post was split to a new topic: Taking a vacation


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.