Transportation


#1



4/7 transportation


this is the error message i got:
the Oops, try again. An error was raised for rental_car_cost(1): local variable 'cost' referenced before assignment


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


can someone please explain to me what i'm doing wrong?


#2

You are seeing this error because you used two equal signs rather than one.

== is for value equality. Use it when you would like to know if two objects have the same value.
= is for declaring or reassigning variables. In your case, this is what you need to do, exactly like the statements you made inside of your if statements.

Let me know if this helps!


#3

def rental_car_cost(days):
cost = days * 40

if days >= 7 :
    cost = days * 40 - 50
elif days >= 3 :
    cost = days * 40 - 20

return cost

this is correct answers please


#4

it did help! thanx so much!


#5

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