0 points
Submitted by Kaylynn Aarons
about 7 years

Error: Maximum Recursion Depth Exceeded

I keep getting an error when I try to run my code. Oops, try again. plane_ride_cost(‘Charlotte’) raised an error: maximum recursion depth exceeded

My code is as follows

def hotel_cost(days):
    return 140 * days

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

def rental_car_cost(days):
    if days <= 2: 
        return (40 * days)
    elif days == 3 or days == 4 or days == 5 or days == 6:
        return (40 * days)-20
    elif days >= 7: 
        return (40 * days)-50

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

Can anyone help me? I’ve been looking through help questions and nothing seem’s to be working… I’ve tried rewriting the code from scratch, but it still comes up with the same error. I just don;t know what I’m doing wrong.

UPDATE: I figured it out. I didn’t do the plane_ride_cost correctly. It had nothing for cost.

Answer 536293e28c1ccc6af30000e6

1 vote


some function is calling itself for an infinite loop

when posting code on the forum, indent it by an additional 4 spaces for it to show properly

Submitted by Jonatan
about 7 years


Kaylynn Aarons about 7 years

Thanks. I understand it now. I didn’t assign cost to anything, and it made it broke. I fixed it now. :)

Jonatan about 7 years

cost? the one you are returning? why would you store it in a variable when you just need to return it, and how would it cause an infinite loop? no, that’s not it. your first line in plane_ride_cost calls plane_ride_cost