Taking a Vacation: Pull It Together Alternative


#1



Hi, I'd just like to ask if we could use the sum function in the exercise, as in sum(days, city, nights) instead of the:
def trip_cost(city, days):
    return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)

That i see the forum using. And if we cannot use the sum function, why not?

Thank you for your time!


#2

sum() is usually utilized to count the sum of a list, so I recommend doing a list, that includes all the items that you must return.

cost = [rental_car_cost(days), plane_ride_cost(city), hotel_cost(days)]

After this you can return sum() of cost, and do whatever you want with it.


#3

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