Week4: Functions Introduction

Functions in a programming language are similar to the functions you have studied for years in mathematics: they perform a task and return a value. As a result, they can greatly enhance the readability of a program and they can make a program easier to write (often by using others' functions).

Readings from the book The Practice of Computing Using Python.

Chapter 5: Functions

Videos

  1. Functions
  2. A function performs a task and often returns a value.

                 def name (parameters):
                    suite-of-statements
                    return something  # optional
                     

    1. Introduction (Video I) (Video II)
    2. Palindrome Functions (Video I) (Video II)
  3. Example using functions.
    1. Car Talk Puzzle (Video I) (Video II)
    2. Driving along, Terry notices that the last four digits on the odometer are palindromic.
      A mile later, the last five digits are palindromic.
      A mile later, the middle four digits are palindromic.
      One mile after that, all six are palindromic.
      What was the odometer reading when Terry first looked at it?

  4. Chapter 5 Exercises on Mimir.
  5. Lab04 (do pre-lab first on D2L)
  6. Project04