Errors in 8.taking a vacation. Help?


#1


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

trip_cost('Charlotte', 0) raised an error: global name 'nights' is not defined


I expect to pass the lesson


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):
    total = days * 40
    
    if days >= 7:
        total -= 50
    elif days >= 3:
        total -=20
    return total
    
def trip_cost(city, days):
    return rental_car_cost(days) == hotel_cost(nights) + plane_ride_cost(city)


#2

This statement needs some revision ...

return rental_car_cost(days) == hotel_cost(nights) + plane_ride_cost(city)

Are you sure you want the == operator in that statement? You need to perform an addition there.

nights is undefined. However, days, which is defined by its being a function parameter, is equivalent to the duration of the stay at the hotel.


#3

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