Stuck on "Pull it Together


Please note, the city being calculated changes each time i.e sometimes it's Charlotte, or the next time it's Pittsburgh.

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

Cannot get the code to add together, keeps having issues with "nights"

def hotel_cost(nights):
    return 140 * nights
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    if city == "Tampa":
        return 220
    if city == "Pittsburgh":
        return 222
    if city == "Los Angeles":
        return 475
def rental_car_cost(days):
    rent = 40 * days
    if days >= 7:
        rent -= 50
    elif days >= 3:
        rent -= 20
    return rent
def trip_cost(city,days):
    return hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)


Hi! The error is in the declared parameter within the function trip_cost, in hotel_cost(nights)... Replace it for days and should work properly. The code of the function should look like this:

Hola! El error se encuentra en el parámetro declarado dentro de la función, en hotel_cost(nights). Reemplazalo por days y debería funcionar correctamente. El código de la función debería quedar así:

def trip_cost(city,days):
    return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)

Good luck!


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