# Pull it Together

#1

Pull it Together

Oops, try again. Make sure to define a function named trip_cost.

I dont know what's wrong. I saw another way to do it by create a variable and add them up. a= b= c=
return a + b + c. which makes sense but i was wondering if my way is correct too if not why and also why it saying that i not defining my function. Thanks in advance.

``````Replace this line with your code.

def hotel_cost(nights):
return 140*nights
# getting there
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
# Transportaion
def rental_car_cost(days):
CostofCar = 40 * days
if days >= 7:
CostofCar -= 50
elif days >=3:
CostofCar -= 20
return CostofCar
# adding all cost together

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

#2

unindent the trip_cost function so that it lines up with the other functions.

#3

That worked thanks again

#4

haha no problem If it's possible, please check it as a solution to show others that it has been solved. Thanks.

#5

Hi all, im pretty sure i have the same code written but i got this error message: "plane_ride_cost('Charlotte') raised an error: maximum recursion depth exceeded"

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

anyone know what's wrong? thanks

#6

You are calling your function, `plan_ride_cost(city)` inside your function, `plane_ride_cost(city)`. This causes an infinite recursion (or a recursion that will never stop hence reaching maximum depth). Your function is supposed to compare your input (parameter) which is `city`. Also, for those return statements, the numbers are supposed to be integers, not strings.

The rest looks good.

#7

ohh ok that makes sense. thank you!!

#8

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