Pull it together


i am stuck in the exercise pull it together
i have understood the logic of computing the total cost
i have defined each block with variables a, b,c
defined a function called add
and return a+b+c
but i get this error message , would be grateful for help
also ,
i am not understanding when we have defined a function forr city cost with arguements night then how do we change this arguement to days, ..

thank you


error message
"Oops, try again. trip_cost('Charlotte', 6) returned 220 instead of the correct value 1243"

    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
    else :
        return plane_ride_cost

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(days)
    return plane_ride_cost(city) 
def add(a,b,c):
    return a+b+c


i have tried using 3 arguements to trip_cost
def trip_cost(city,nights, days):

return rental_car_cost(days)
return hotel_cost(nights)
return plane_ride_cost(city) 

def add(a,b,c):
return a+b+c
but it returns a error i should use only 2..!


It returns 220 because that is the rental car cost. All the other code after this return is unreachable.

The exercise instructions do not ask for a function, add. so to be on spec that should be removed.

If you remove all the return lines, keep the lower three and then return the sum, everything will work out.

return a + b + c

One last thing, the trip_cost function has a days parameter, not, nights. That variable is a local to the hotel_cost function. Use only the days variable when calling it. Remove that parameter from the trip_cost function.


o great thank you
i think i unnecessarily complicated it ,
i just followed your advice
and struck down lot of things .. finally it came down to just this which worked

def trip_cost(city, days):    
    a = rental_car_cost(days)
    b = hotel_cost(days)
    c = plane_ride_cost(city)
    return a + b + c


That looks sensible, would you not agree?


thank you, i didn't realize ..


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