HELP ERROR! trip_cost('Los Angeles', 7) raised an error: sum expected at most 2 arguments, got 3


#1



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

trip_cost('Los Angeles', 7) raised an error: sum expected at most 2 arguments, got 3

I don't understand why my code doesn't work. It gives an error that the sum is getting three arguments when I am only giving two. Can somebody please help me?


def hotel_cost(days):
    Price_per_night = 140
    Total = Price_per_night*days
    return Total

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):
    if days >= 7:
        total = 40*days - 50
        return total
    elif days >= 3 and days < 7:
        total = 40*days - 20
        return total
    else:
        total = 40*days
        return total

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


#2

Hi @matss94 ,

Here, you passed three arguments to sum ...

return sum(rental_car_cost(days),hotel_cost(days),plane_ride_cost(city))

If you would like to use sum to total up some values, then enclose the values in a list, so that you can pass the list as a single argument ...

return sum([rental_car_cost(days),hotel_cost(days),plane_ride_cost(city)])

Note that the square brackets were used to create a list. But your code would be clearer if you used the + operator instead to add up the values ...

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