Getting a maxim recursion depth error and I dont know why on 5/7


#1

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

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

This is the code and the error is:

rental_car_cost(1) raised an error: maximum recursion depth exceeded


#2

There is your recursion.


#3

A function calling itself is recursion, and if you don’t have a base case, your function will keep calling itself until the maximum depth is reached, sort of like an infinity loop, but with function calls.


#4

I just need to change this part?


#5

yep


#6

Examine your other two return lines, and write one at the end that does not subtract anything from cost.


#7

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