Exercises
Here are some exercises for you to try on your own. Solutions are available at http://pragprog.com/titles/gwpy3/practical-programming.
-
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 ...
Get Practical Programming, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.