Local variable 'cost' referenced before assignment. :(


#1



I am stuck on taking a vacation.

It keeps telling me "Oops, try again. An error was raised for rental_car_cost(1): local variable 'cost' referenced before assignment."


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


#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!