Functions are helpful because they give us the ability to organize pieces of reusable code, then refer to those pieces later in our programs by a single short name or command.

Putting Things Together

To make a piece of code reusable later, or just easier to read now, we can define a function and give it an easy-to-understand name. Defining a function is also called declaring the function, and it just means that we’re telling the computer what we want the function to do.

Parameters

Return

Interaction

ClickKaleidoscope

Summary

At this point, you should be able to do the following:

  1. Make code more reusable using functions.
  2. Organize and group code into functions.
  3. Define functions in Python using the def keyword.
  4. Call your own functions from programs that you write.
  5. Define and use functions that accept parameters as input values.
  6. Write functions that return values when called.
  7. Convert a mathematical formula into a function that returns the function’s value.
  8. Explain some features of event-driven programs.
  9. Write a basic event-driven app that uses an event handler.
  10. Write an app that accepts mouse clicks and draws on the screen.
  11. Code event handlers for keyboard events.
  12. Program event handler functions that take parameters.
  13. Use x- and y-coordinates on the screen to draw specific patterns, such as kaleidoscopes.

Challenges