Local variable 'cost' referenced before assignment. :(



<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?


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>



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


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


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.”


Your return should be outside of else


like this? else days < 3:
return cost

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

just go back one indent with return cost


Thank you! that worked!