# Pull It Together, returning incorrect values

#1

Lesson 5 Pull It Together

Each time I try to save and submit, I get errors like this:

Oops, try again. trip_cost('Los Angeles', 1) returned 40 instead of the correct value 655
Oops, try again. trip_cost('Los Angeles', 5) returned 180 instead of the correct value 1355
Oops, try again. trip_cost('Tampa', 9) returned 310 instead of the correct value 1790
Oops, try again. trip_cost('Tampa', 7) returned 230 instead of the correct value 1430
....etc.

It shows different cities and values each time, randomly it seems. I'm unsure where the bug is.

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

#2

why do you have an add function? You can calculate the total trip cost in trip_cost function

a function ends the moment a return keyword is reached, so currently, you only charge travelers for there rental car, not for there hotel or plane ride

#3

Thanks for pointing that out. I had the add function there because the instructions made a reference to the example at the top of the lesson.

I took out the add function, and now have this,

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

Now I have this error.

Oops, try again. trip_cost('Pittsburgh', 6) raised an error: global name 'nights' is not defined

#4

here:

``hotel_cost(nights)``

this should be days, nights isn't defined anywhere.

#5

Oh I see, nights was an argument of a different function. It works now, thanks for your help!

#6

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