2.6. Exercises#
Two of Python’s built-in functions are min and max. In the Python shell, execute the following function calls:
min(2, 3, 4)
max(2, -3, 4, 7, -5)
max(2, -3, min(4, 7), -5)
For the following function calls, in what order are the subexpressions evaluated?
min(max(3, 4), abs(-5))
abs(min(4, 6, max(2, 8)))
round(max(5.572, 3.258), abs(-2))
Following the function design recipe, define a function that has one parameter, a number, and returns that number tripled.
Following the function design recipe, define a function that has two parameters, both of which are numbers, and returns the absolute value of the difference of the two. Hint: Call built-in function abs.
Following the function design recipe, define a function that has one parameter, a distance in kilometers, and returns the distance in miles. (There are 1.6 kilometers per mile.)
Following the function design recipe, define a function that has three parameters, grades between 0 and 100 inclusive, and returns the average of those grades.
Following the function design recipe, define a function that has four parameters, all of them grades between 0 and 100 inclusive, and returns the average of the best 3 of those grades. Hint: Call the function that you defined in the previous exercise.