Transportation


#1



https://www.codecademy.com/courses/python-beginner-P5YtY/1/3?curriculum_id=4f89dab3d788890003000096#


When I submit it, the message comes up " An error was raised for rental_car_cost(1): local variable 'cost' referenced before assignment


I don't know what I'm doing wrong! Please help.


def hotel_cost(nights):
    return 140*nights
    
def plane_ride_cost(city):
  if city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    elif city =="Pittsburgh": 
        return 222
    elif city == "Los Angeles":
        return 475

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


#2

cost will be True since 40 * days will be non-zero when days is non-zero.

Operators

==   comparison

<=   comparison

>=   comparison

>    comparison

<    comparison

=    assignment

Once this is sorted out, you will only need to return cost at the end. (That means the else branch is not needed.)


#3

Thank you so much!!!


#5

This topic is solved.