Transportation- car renta


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

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


That's as far into the function as we get. return days * 40.

Consider creating a variable, cost and store the above amount. Then test the number of days and where applicable, subtract the discount. Don't use return until the end of the function.


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

i created a variable, but i am still getting stuck


If the part you posted is your whole function I think you finaly need to return the cost when days are less than 3.


Which sums it up.

return cost

at the end of the function. This is called fall through. The values that hit this point are stragglers. To satisfy some desire to complete the if statement we could write,

    return cost


i have the save problem here


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