Pull it Together


#1

why do we have to change hotel_cost(nights) to hotel_cost(days) when returning hotel_cost...

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 hotel_cost_(_nights_)_ + plane_ride_cost(city) + rental_car_cost(days)**
    print trip_cost("Tampa", 3)

Doesn't work, however...

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 hotel_cost(_days_) + plane_ride_cost(city) + rental_car_cost(days)**
    print trip_cost("Tampa", 3)

Does work.

The original function was hotel_cost(nights): not hotel_cost(days):

Surely it should stay the same? I'm very confused.


#2

yes, but a function parameter (night) is a placeholder, when you call the hotel_cost you provide days as argument, so night will get the value of days, look:

def example1(parameter1):
   print parameter1
def example2(parameter2):
   example1(parameter2)
example2("hello world")

when you call example2, you provide "hello world" as argument to parameter2. then you provide parameter2 as argument to example1, so now parameter1 will hold the value of parameter2, which in its turn contains hello world


#3

try this in your rental_car_cost(days)....
instead of using cost -=50
use this method return cost - 50

i hope it can help


#4

sometimes there are multiply ways to solve a problem, both your and ndna solution are correct, and it was not really what the question was about


#5

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