Exercises

Here are some exercises for you to try on your own. Solutions are available at http://pragprog.com/titles/gwpy3/practical-programming.

  1. Two of Python’s built-in functions are min and max. In the Python shell, execute the following function calls:

    1. min(2, 3, 4)
    2. max(2, -3, 4, 7, -5)
    3. max(2, -3, min(4, 7), -5)
  2. For the following function calls, in what order are the subexpressions evaluated?

    1. min(max(3, 4), abs(-5))
    2. abs(min(4, 6, max(2, 8)))
    3. round(max(5.572, 3.258), abs(-2))
  3. Following the function design recipe, define a function that has one parameter, a number, and returns that number tripled.

  4. 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.