Please Explain This Stupid Syntax Error


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

It give me a syntax error on elif statement. Please explain what I am doing wrong.


return is very important keyword,
Few things to keep in mind..

1.It is used inside functions.
2.It acts as exit door of a function,It means when function hits/sees it ,It returns the part (value) attached to it and halts the process, code after return statement does not get a chance to get executed.

Second line of your code,same thing is happening there.
We also need to make changes inside our if/else clause.

If you read instruction one more time you willl find
that its written 40/day is general rental cost .
We are giving days as parameter here so We can create a general expression that will calculate rental cost based on number of days.

You can name it anything.. say
rental_cost = days * per_day_rate (per_day_rate is 40, right?)

You have to make same changes inside your if/elif/else statements.


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