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

Tried loads of different ways been stuck for ages. obviously theres something wrong. something not being defined as it comes back as none. tried defining days didnt seem to work. tried defining cost different also tried doing it like in the previous tasks. im doing something wrong!!

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


well, if we can add a function call:

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

print rental_car_cost(x)

where x is the number of days. You will see that for one or two days, the correct amount is returned. Not for other days

You always need to return cost

when the if condition is true, elif and else won't execute


i added the print function at the end. Still comes back with the same message.


the print statement was for you to show you when a return keyword is (or isn't reached), so you can see where you go wrong (by changing x into the number of days (for example 4))

Of course if you adding the print statement will still give you an error message, as i explained in my answer.

Help != instant solution


So elif statement needs to be executed but i dont know how. Whats the Help != instant solution about?


the elif statement executes, but it doesn't return anything.

That the forum is for helping, not getting instant solutions. Your reply:

suggested adding a print statement would instantly fix your problem


Not asking for you to give me a answer. Just some help!! Im not a developer. Just wanted to know why my elif statment doesnt return anything and why the rest of my code doesnt work.


because a return keyword is only reached when else runs


you can do it with only one return statement, but you need to take return out of the conditional block by lining it up with the if and elif:

if a:
then b
elif c:
then d

also make sure your cost statements are correct and your indentations are exactly 4 spaces


don't indent the return is what I meant to say.


this approach would work if he update cost. @jhcroydon you have two options, or add return inside if and elif or update cost and then return cost in the end (without else)


Yes, thank you for that.


what do you mean lining it up with if and elif?


If you look at the example with tickets you will see what I mean. The if, elif, and return are aligned left (not indented).



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