Transportation


#1

Hi. What am I doing wrong?

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

My error is:
It looks like rental_car_cost returns None instead of the correct amount (100) for 3 days.

Thanks in advance!!


#2

from the way you define your function, the function will only return a cost only if the function enters the "else:" block of code (i.e. days <=3).

so, you can fix this either by:
1) entering "return cost" both under the "if" statement and "elif" statement (note: the indentation should be the same as the cost =- 50/20 part)
2) entering "return cost" under the whole block (i.e. same indentation as the if and elif statements). with this method, you could do away the "else" block of code too.


#3

Hi. Thanks for replying. I solved it.


#4

Dude i did your number 2 method already earlier . Here is what i code :

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

Yet the answer is : 40
None
And i got this message :
Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days.

HELP ME PLEASE !!!!


#5

change your "print money" to "return money". I can't see your indentation but make sure the return money is of the same indentation as the if statement.