# Pull it together

#1

So I already figured out a way to how this code works but in the instructions it tells us to use sum().

"Like the example above, have your function return the sum of calling the rental_car_cost(days), hotel_cost(days), and plane_ride_cost(city) functions."

I don't understand how it wants us to use a sum() if there are three functions it wants us to add. The only way I could see me using sum() is if I define another function and within that function I add two of those three functions together. Then add the new function that I just created with one of the functions I didn't put in the new one.

Ex.
def A
def B
def C
'''def Z:
return sum(A, B, C) this wont work because 3 functions'''
def D
return A + B
def E
return sum(D, C)

``````def hotel_cost(days):
return 140 * days

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

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

#2

So I already figured out a way to how this code works but in the instructions it tells us to use sum().

It does not want you to use `sum` function. It simply wants you to use addition.

Instruction says:

Like the example above, have your function return the sum of calling the rental_car_cost(days), hotel_cost(days), and plane_ride_cost(city) functions.

This is the code from the example above:

``````def double(n):
return 2 * n
def triple(p):
return 3 * p

return double(a) + triple(b)``````

No `sum()` here, right?

But if you would like to use `sum` you can use this code:

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

#3

Ah ■■■■, I just assumed it wanted us to use the sum function because it was bolded. Thanks a million anyhow.

#4

I understand You're very welcome.

#6

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