7. Plan Your Trip! - Why replacing hotel_cost(nights) with hotel_cost(days) works?


7 Plan Your Trip!

Hello everyone! I'm a total beginner with programming and coding, I think I need some extra help to understand some of these exercises.

I managed to complete the task 7. Plan Your Trip!, the fact is I think I missed why it actually works. To be precise, why replacing hotel_cost(nights) with hotel_cost(days) still makes the whole function work? I can't see how hotel_cost(nights) and rental_car_cost(days) are related, can someone explain it to me?

(I tried to add a fourth argument to the final function making no changes to the hotel_cost(nights) function, the result is the same, but the exercise requires me to solve it exactly with three arguments)

Thanks for the help.

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

print trip_cost("Los Angeles", 5, 600)


The days variable is defined in the parameter list. It is the local reference for the value passed in that represents how many days (or nights). We need to pass that variable to hotel_cost() but that function can define its parameters any way it suits. The name is irrelevant. It's the value that is being passed along that matters.


A post was split to a new topic: Nothing is printing to the screen