4/7 won't read if statement


#1

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

the error says "It looks like rental_car_cost returns 120 instead of the correct amount (100) for 3 days" :confused:


#2

The function rental_car_cost returns days * 40. So it exits the function before it can read the if-else statements.

Instead, in the function, just work on a variable called 'cost' and return it at the end (as opposed to three return commands)

Something like this-

def rental_car_cost(days): 
    cost = days * 40
    if days >= 7:
        cost -= 30
    elif days >= 3:
        cost -= 20
    return cost

Or you can still use multiple return statements, but set cost to 40 * days first, and then keep the if elif statements the same. Also add an else statement that returns the original cost, if both conditions arent satisfied.