4/7. Transportation


#1

Hey guys!

I wrote my code. It seems like right

14 def rental_car_cost(days):
15 cost = days * 40
16 if days >= 7:
17 cost -= 50
18 elif days >= 3 and days < 7:
19 cost -= 20
20 return cost

but in console it gives me this error.

File “python”, line 20
SyntaxError: ‘return’ outside function

and I cannot find a solution.
Has anybody experienced something like that? Could you please help me to figure it out?


#2

this is currently your function definition + function content/body:

def rental_car_cost(days):
    cost = days * 40

the rest of the code is outside the function. Indention determines nesting (so what is nested inside the function)


#4

I know, that is why i said the if, elif clause and return are outside the function due to the way these lines are indented. Actually, i said the opposite, what was inside your function body, from which you conclude that if, elif and return where outside the function body.


#5

Thanks a lot. Now I see. :slight_smile:


#6

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