Maximum Recursion Depth Exceeded


#1

plane_ride_cost('Charlotte') raised an error: maximum recursion depth exceeded is the error for

def hotel_cost(nights):
return 140 * nights

def plane_ride_cost(city):
if plane_ride_cost ("Charlotte"):
return 183
if plane_ride_cost ("Tampa"):
return 220
if plane_ride_cost ("Pittsburgh"):
return 222
if plane_ride_cost ("Los Angeles"):
return 475

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

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


#2

@courseninja22453,

If you write code like

def plane_ride_cost(city):
    if plane_ride_cost ("Charlotte"):
        return 183

you are calling plane_ride_cost() within the function plane_ride_cost() again and again
until you reach the so-called maximum recursion depth

Change your code like

def plane_ride_cost(city):
    if city == "Charlotte":
        return 183

====================

A recursion is when a function is calling upon itself.
A recursion can be and is used for special purposes,
but the function should have a build-in exit-strategy, otherwise
you will run against the wall being the so-called max-depth parameter.
Depending on the computer-type, the memory, the parser, and the browser used,
this max-depth parameter varies from 276 upontill 255000.
google search
== discussions / opinions ==
python maximum recursion depth exceeded site:stackoverflow.com
for instance
= http://stackoverflow.com/questions/8177073/python-maximum-recursion-depth-exceeded


#3

i'm having the same problem but with hotel_cost(days) please help