Lab Description:
This lab shows students how to create functions in python. There are two type of functions in python, which they are built-in functions and functions created by the writer (developer). The built-in functions allows you to do some actions such as the “print()” functions, make python ask the user for an “input()”, convert floats into integer and visa versa, and much more. In the other hand for writers to write their own functions they have to define them by typing “def X():” (X represent any name you desire to call that function. For step one, we see that an function is written and it returns the constant 42 as an example of how to write a function and what can that function do afterwards. Between the parenthesis in your function you should place a parameter, if necessary, in order for that functions to return the values of any conditional that it meets which is true as later on it is shown. In step two, we create a new function called “hotel_cost” which take the argument of “nights” and it would return the value of the cost of the amount of nights multiply by 140 (money). In step three, we created another functions called “plane_ride” which it takes the argument “city” and this functions calculates the cost of a flight to a specific city. For the second function we have to create a set of conditionals that meets a requirement later on. As it is shown in step three, the “if” and “elif” statements in order for the function to return a value depending on the city that is chosen later. In step four, a function for the cost of a car that is rent is define and it take the argument “days”. This functions also uses statements where it takes the cost of the rent depending on how many days and the variable cost is set to the values of days * 40 which the function would return later on. The fifth step is to create another function in which it take values and makes the other functions to return the total cost of the trip. For this function, the arguments that it takes are city and days and it would return the sum of all the other values that the functions gives back. We set the second function (hotel_cost) to take the argument days which replaces the nights argument in order to type less values. Later on we added another argument to the last function which it would add up with the other functions. At the last step we can see all the functions written playing their role where it returns a result when we print the last function and setting some values from the others functions including a city, days, and a amount of money.