Transportation (Returns None Error)


Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days.

can't pinpoint what's wrong with this one. I thought everything I did was right.

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


I believe that they want you to subtract 50 from the total amount if the number of days is greater than or equal to 7.


now whatever I do, I get that same error.
tried all remedy I see in other threads.
I also refreshed the whole page, but it's still giving me the same error.



I did my code different to yours, instead of cost I used days.

def rental_car_cost(days):
if days >= 7:
return 40 * days - 50
........etc, etc

I also tried cost = 40 * days and got the same response. I changed my approach and focused on days and left cost completely out of my code.

It worked and I added a print command at the end - print rental_car_cost(add any number here) to see if it actually did the calculations correctly. Of course I did first work out what the cost would be before hand on a piece of paper to make sure it actually did the calculations correctly.

I hoped this helped, being a beginner myself I know how frustrating it is to think outside the examples that are provided for us.


Thanks! Guess I should also start thinking of different approaches rather than just plainly follow them.


Glad I could help. I will admit that my other approach was not immediate, it took some time to puzzle it out.


try this

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


having the same issue as above, can you explain why this works?


What issue are you having and can I see your code?


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

I have the correct indents. I found that adding "return cost" as an else statement fixes the problem. I am wondering why that is


That is because if the days driven is neither equal to the if or elif statements(for example if days=1) it should just return the cost. Adding that else statement will fix your problem.


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