Pulling it all together.... Please help!



It says maximum recursion depth exceeded

i dont know what is wrong

def hotel_cost(nights):
    return hotel_cost(140 * nights)
def plane_ride_cost(city):
    if city=="Charlotte":
        print plane_ride_cost ('Charlotte')
        return 183
    elif city=="Tampa":
        print plane_ride_cost ('Tampa')
        return 220
    elif city=="Pittsburgh":
        print plane_ride_cost ('Pittsburgh')
        return 222
    elif city=="Los Angeles":
        print plane_ride_cost ('Los Angeles')
        return 475
def rental_car_cost(days):
    cost = 40 * days
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    return cost
def trip_cost(city, days, spending_money):
    return hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)
    print trip_cost



Delete all the print plane_ride_cost lines. (I went through the lessons I could not find this instruction to place a print after every city).
Trip_cost only has two arguments - you have 3.

Hope that helps.


I don't really understand recursion and I'm not good at composing speech. And so I'll try to explain it with code, but only in the frame of the problem.

def hotel_cost(nights):
return hotel_cost(140 * nights)

is very simmilar to

def f(x):
return f(x + 1)

And if we pass it the number 42 for example:

f(42) returns f(42 + 1) which returns f(43) which in turn returns f(43 + 1) > f(44) > f(44 + 1) > f(45)

and so on and on with the final result ever eluding, until something external stops the program from going further.
Same with the function plane_ride_cost(city). You're trying to print the result before you have the result.

And as for any other possible problems carl1n and I haven't mentioned, you're perfectly ready to solve yourself. Remember that you don't know if your "bag of tools" has the tool for the problem until you try and if you don't have it, then in this process you might re/invent it!


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