What is wrong in this code?


#1

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

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


#2

You won't be returning cost for the first two conditions.
Consider moving your return statement outside like this so it applies to any condition rather than just your else:

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

#3

Thanks a lot! I'm new to python


#4

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