Teach Your Kids To Code: A Parent-friendly Guide to Python Programming

(vip2019) #1

172 Chapter 7


What You Learned


In this chapter, you learned how to organize chunks of reusable
code into functions, call your own functions from anywhere in your
programs, pass information as parameters to those functions, and
get information back from functions as return values. We wrote
our first event-driven programs by telling the computer to listen
for mouse clicks and keypresses, and you learned how to write
your own callback functions to respond to user events.
We’ve developed our first fully interactive programs. Using the
skills you’ve gained in this chapter, you’re ready to begin writing
even more advanced apps. The apps we frequently enjoy give users
the experience of being in control of the program by responding to
clicks, touches, keypresses, and more.
After mastering the concepts in this chapter, you should be
able to do the following:
• Make code more reusable using functions.
• Organize and group code into functions.
• Define functions in Python using the def keyword.
• Call your own functions from programs that you write.
• Define and use functions that accept parameters as input
values.
• Write functions that return values when called.
• Convert a mathematical formula into a function that returns
the function’s value.
• Explain some features of event-driven programs.
• Write a basic event-driven app that uses an event handler.
• Write an app that accepts mouse clicks and draws on the
screen.
• Code event handlers for keyboard events.
• Program event handler functions that take parameters.
• Use x- and y-coordinates on the screen to draw specific
patterns, such as kaleidoscopes.
Free download pdf