Transportation- car renta

#1

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

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

#2

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.

#3

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

#4

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

#5

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,

``````else:
return cost``````

#6

i have the save problem here

#7

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