Please tell me what is wrong with my code?


#1



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


Oops, try again. trip_cost('Charlotte', 7) returned 1113 instead of the correct value 1393
What is wrong with this code??


def hotel_cost(night):
    return 140*night
night = 5
def plane_ride_cost(city):
    if city == "Pittsburgh":
        return 222
    elif city == "Los Angeles":
        return 475
    elif city == "Charlotte":
        return 183
    elif city == "Tampa":
        return 220
    else:
        return "booboo"
city = "Los Angeles"
def rental_car_cost(days):
    day = 40
    d = days * day
    if days < 3:
        return d
    elif days >= 7:
        d -= 50
        return d
    elif days >= 3:
        d -= 20
        return d
days = 5
def trip_cost(city, days):
    return hotel_cost(night) + rental_car_cost(days) + plane_ride_cost(city)
days = 5
d = 5
city = "Los Angeles"


#2

Recall that local variables (those defined inside a function) are not seen in the global namespace.

The instructions ask for nights as the local variable (parameter) of the hotel_cost function. We cannot use that variable to call the function since it is not defined in that scope. Use the days variable in this call since it is defined in the calling scope.


#3

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