Cost Not Returning Correctly


#1

Taking a Vacation 4. Transportation

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

I need rental_car_cost to return 100 for 3 days.

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

Hi, @saretheshi ,

You have this first in the rental_car_cost function ...

return 40 * days

Actually, that is what should be executed in the event that days is less than 3, which would be the case when the if and the elif conditions are False.

Consider where that statement should be moved in order for that requirement to be satisfied.


#3

I'm trying to make the cost return 100 for 3 day, but instead it's returning 120.


#4

That will not happen if this statement is first because after it is executed, the function will terminate and return a result, and none of the other statements will get executed ...

return 40 * days

#5

Thank you, my mind was going elsewhere


#6

Consider where the statement should be placed instead of where it is now.


#7

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