3 days returning 120 instead of 100?


#1


https://www.codecademy.com/courses/python-beginner-P5YtY/1/3?curriculum_id=4f89dab3d788890003000096#

Renting the car for three days should return $100, but I'm getting $120. What am i doing wrong?


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


#2

Simpler to create a variable and use one return statement at the end of the function.

cost = 40 * days
if days >= 7:
    cost -= 50
elif days >= 3:
    cost -= 30
return cost

#3

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