# "Pull it Together" help!

#1

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

I'm having trouble understanding why this happens, I'm so lost this unit. Any help is greatly appreciated!!

``````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
else:
return "NULL"

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

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

#2

This is where your error is coming from, you're calling the function from within the function, and it's causing a type of infinite loop.
you just want to write:

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

and this will be enough.

The other thing i wanted to point out though, is that you use

``````else:
return "NULL"``````

If there is no condition that will fall under `else`, just don't write an else statement, so you can get rid of those two lines.

#3

Thanks so much!
Although now it returns
"Oops, try again. trip_cost('Charlotte', 7) returned None instead of the correct value 1393"

def hotel_cost(nights):
return 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
else:
return cost

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

#4

you need to write `return` before here, so it would be

``return trip_cost = hotel_cost(days)+plane_ride_cost(city)+rental_car_cost(days)``

#5

i write that line + return and it did'nt got right..

why?

#6

return trip_cost at last

#7

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