Local variable 'cost' referenced before assignment. :(


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
I am stuck on taking a vacation.
<In what way does your code behave incorrectly? Include ALL error messages.>
It keeps telling me “Oops, try again. An error was raised for rental_car_cost(1): local variable ‘cost’ referenced before assignment.”

<What do you expect to happen instead?>
Everything seems to have correct syntax. What am I missing?

```python

Replace this line with your code.
def rental_car_cost(days):
cost == 40 * days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost

<do not remove the three backticks above>

#2

Hi

you don’t need to put two = to give a value to a variable. The double == means that you are comparing two things together in order to obtain a boolean value. In order to give a value to a variable, you write it

cost = 40 * days

#3

This line is wrong

cost == 40 * days

local variable ‘cost’ referenced before assignment

you need to assign 40 * days to cost

== is equal

and your return should be outside of else


#4

Thanks for answering! I took one of those equal signs out and now it is saying this “Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days.”


#5

Your return should be outside of else


#6

like this? else days < 3:
return cost


#7
elif days >= 3:
    cost -= 20
return cost

just go back one indent with return cost


#8

Thank you! that worked!