Skip to Content
Learn
Taking a Vacation
Pull it Together

Great! Now that you’ve got your 3 main costs figured out, let’s put them together in order to find the total cost of your trip.

def double(n): return 2 * n def triple(p): return 3 * p def add(a, b): return double(a) + triple(b)
  1. We define two simple functions, double(n) and triple(p) that return 2 times or 3 times their input. Notice that they have n and p as their arguments

  2. We define a third function, add(a, b) that returns the sum of the previous two functions when called with a and b, respectively. Notice that even though the names of the parameters for add(a, b) are different than the names of the parameters for double(n) and triple(p) we can still pass them into those functions as arguments

Instructions

1.

Below your existing code, define a function called trip_cost that takes two parameters, city and days and returns the sum of calling the rental_car_cost(days), hotel_cost(days - 1), and plane_ride_cost(city) functions.

Notice that we changed the argument of hotel_costs() from nights to days - 1. Since we want trip-cost to only depend on two parameters, we have to convert the variable nights into days. If you are going to be staying somewhere, the number of nights you stay there is one less than the number of days you were there (imagine a weekend trip to visit family, you leave Saturday and return Sunday, so you visit for two days, but only stay for one night).

Folder Icon

Take this course for free

Already have an account?