Taking A Vacation

“Taking A Vacation”

Throughout this exercise, I gain the understanding of the else, elif and the if statements. At the start of the exercise a review of the return statement.  The computer ask for a return statement of 42. So we first define the function, answer, with an empty argument. We return the number, 42. The result should be the number 42.

tv-1

 

The next three screenshots indicates three functions, hotel_cost which takes the argument nights, plane_ride_cost which takes the argument city and the last function rental_car_cost with the argument days.

The first function is defined is hotel_cost with an argument called night. A return statement of 140 times the night is inputted.

tv-2

Another function is defined plan_ride_cost with an argument called city. An if statement takes the variable city to equal to “Charlotte”, with a return statement of 187. This is indicating that if Charlotte was inputted by a user, the number 187 would appear. The elif statement is s used twice for the “Tampa” which returns 220 and “Pittsburgh” which returns 222. The last statement, else, is used for the last city “Los Angles” which returns to 475.

snip20161101_15

 

The next function that is defined will be rental_car_cost with an argument, days. We input the data of cost to equal to 40 times day. An if statement use days as the variable and set it to equal or greater than 7 days , in which the return statement will be the total days minus 50. The elif statement is inputted with days being equal to or more than 3 days, in which the return statement will be the total days minus 20.

tv-4

A return statement of the rental_car_cost definition is inputted at the end.

The function we are defining next is trip_cost with the arguments of city and days, (city,days). We return with adding all the functions was defined, plan_ride_cost(city) + hotel_cost(days) + rental_car_cost(days). This will give the total of the whole trip.

 

tv-5

Of course, when you do go out for the trip, you’re not just going to spend it only on the travel expenses. You may want to buy a souvenir, so let’s add spending_money.

tv-6