In this lab, we created a program using functions. Functions allow us to add an input to execute a command to.

In this screenshot, we used the keyword “def” to tell python we are creating a function. I entered into “answer” as the function named and placed parentheses and semicolon next to the function name. When you call this function it will return the value 42.


In this screenshot, I created a function named “hotel_cost”. The argument it takes in is nights. It returns the result from $140 * nights. The argument “nights” can take any number; for an example, if nights was 2, it would take the number 2 replace it with nights in the return keyword and multiply 2 to 140.


In this screenshot, I created a function named “plane_ride_cost” with the argument “city”. The instructions say to return the values of Charlotte, Tampa, Pittsburgh, and Los Angeles with its respective values. I used if and elif statements to allow this function to work. I used the if statement because if you place the city name into the argument it should be able to return the value of that city’s plane ride cost.


In this screenshot, I created a function “rental_car_cost” with the argument “days”. This function takes the amount of days and calculates how much a car would cost with the amount of days rented. I assigned the variable “cost” to days * 40 because everyday you rent a car, it cost $40.  If you rent the car for more than 7 days it will be cost – 50 because you get a $50 discount for renting it for more than 7 days. For a rental car for 3 days or more you get a $20 discount. However, you cannot get both of the discounts.


In this section, I created a function named “trip_cost” with the argument “city” and “days”. This takes the functions rental_car_cost, hotel_cost, and plane_ride_cost and adds them together. “rental_car_cost” takes the argument “days” because it takes the rental cost of the car per day. “hotel_cost” also takes the argument “days” because it is the amount of nights a person can stay at their hotel. “plane_ride_cost” takes the argument “city” because it will take the value of the plane ride cost for the city they are traveling to.


In this section, I added another argument to “trip_cost” named “spending_money”. I also added the variable into the equation.


Finally, I printed the result of trip_cost. I used the arguments “Los Angeles”, “5”, and “600” in that respective order to get the result of $1955.