Taking a vacation


#1

Wondering why this won't compile:

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):
return 40*days
if days>=7:
return 40*days -50
elif days>=3:
return 40*days -20


#2

. It looks like rental_car_cost returns 120 instead of the correct amount (100) for 3 days.


#3

Hi @alike44,

Within the rental_car_cost function, move this to the end ...

    return 40*days

Where it is now, it executes as the function begins execution, and the other two conditions are not considered at all. When it is moved to after the other two conditions, it will execute if those conditions are not satisfied.


#4

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):
if days>=7:
return 40*days-50

if days>=3:
    return days*40 -20

elif days<3:
    return days*40
def trip_cost(City, days):
    return   rental_car_cost(days) +  hotel_cost(nights) + plane_ride_cost(city)

this won't compile still also


#5

The trip_cost function has some problems.

Make sure that the function header is not indented. Change the City parameter to city. Within the function, pass days instead of the undefined nights to the hotel_cost function. After the corrections, you should have ...

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

#6

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