# Returning trip_cost doesn't work

#1

Please, can anyone detect what is wrong?

Oops, try again. hotel_cost(1) returned 40 instead of the correct value 140

``````def rental_car_cost(days):
return 140*days
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 hotel_cost(days):
cost = 40 * days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost
def trip_cost(days, city):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)``````

#2

yea, you seemed to have swapped the rental_car_cost function with the hotel_cost function. hotel_cost should return 140*days, currently your rental car cost function is doing this

#3

i actually tried to swap them but it returns another mistake: hotel_cost(3) returned 400 instead of the correct value 420
(car cost is in fact supposed to be *40)
any ideas? i'm super annoyed at this point

#4

can i see an updated version of your code?

#5

def rental_car_cost(days):
return 40 * days
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 hotel_cost(days):
cost = 140 * days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost
def trip_cost(days, city):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)

and error message is hotel_cost(3) returned 400 instead of the correct value 420

#6

you didn't understand what i was saying. You have two functions, rental_car_cost and hotel_cost:

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

but the content of your rental_car_cost should be in the hotel cost function:

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

and vice versa, you literally swapped the function (content). Take a look at the earlier exercises to see how it should be

#7

■■■■!
ok swapped it. a whole different error:(
trip_cost('Tampa', 9) raised an error: unsupported operand type(s) for -=: 'str' and 'int'
and this appears for all locations

#8

#9

I have the same problem
Look at my code which has an error,

``````Oops, try again.
It looks like nothing was printed to the console!``````

``````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, spending_money):
return rental_car_cost(days) + hotel_cost(days)+ plane_ride_cost(city) + spending_money
print trip_cost("Los Angeles", 5, 600)``````

#10

No, you have a different problem. In fact you are at a different exercise

Solution: the function call (of trip_cost) should be outside the function (hint: indention)

#11

thanks for sticking here... really lost.
the eror is: trip_cost('Los Angeles', 0) raised an error: unsupported operand type(s) for -=: 'str' and 'int'

``````def hotel_cost(days):
return 140 * days
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:
cost -= 50
elif days >= 3:
cost -= 20
return cost
def trip_cost(days, city):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)``````

#12

when the exercise calls the function:

`` trip_cost('Los Angeles', 0)``

city is the first argument, days the second. But your function:

``def trip_cost(days, city):``

days is the first parameter, and city the second. This obviously causes errors. You are good at swapping things

#13

finally!
i'm so grateful
haha yes all this programming thing is new for me, will try to work cleaner
and thanks again:)

#14

I can't figure it out yet

#16