Python for Kids

Book description

For Kids Aged 10+ (And Their Parents)

The code in this book runs on almost anything: Windows, Mac, Linux, even an OLPC laptop or Raspberry Pi!

Python is a powerful, expressive programming language that's easy to learn and fun to use! But books about learning to program in Python can be kind of dull, gray, and boring, and that's no fun for anyone.

Python for Kids brings Python to life and brings you (and your parents) into the world of programming. The ever-patient Jason R. Briggs will guide you through the basics as you experiment with unique (and often hilarious) example programs that feature ravenous monsters, secret agents, thieving ravens, and more. New terms are defined; code is colored, dissected, and explained; and quirky, full-color illustrations keep things on the lighter side.

Chapters end with programming puzzles designed to stretch your brain and strengthen your understanding. By the end of the book you'll have programmed two complete games: a clone of the famous Pong and "Mr. Stick Man Races for the Exit"—a platform game with jumps, animation, and much more.

As you strike out on your programming adventure, you'll learn how to:

  • Use fundamental data structures like lists, tuples, and maps
  • Organize and reuse your code with functions and modules
  • Use control structures like loops and conditional statements
  • Draw shapes and patterns with Python's turtle module
  • Create games, animations, and other graphical wonders with tkinter

Why should serious adults have all the fun? Python for Kids is your ticket into the amazing world of computer programming.

Publisher resources

View/Submit Errata

Table of contents

  1. Cover Page
  2. Praise for Python for Kids
  3. Title Page
  4. Copyright Page
  5. Brief Contents
  6. Contents in Detail
  7. About the Author
  8. About the Illustrator
  9. About the Technical Reviewers
  10. Acknowledgments
  11. Introduction
    1. Why Python?
    2. How to Learn to Code
    3. Who Should Read This Book
    4. What’s in This Book
    5. The Companion Website
    6. Have Fun!
  12. Part I: Learning to Program
    1. Chapter 1: Not All Snakes Slither
      1. A Few Words About Language
      2. Installing Python
        1. Installing Python on Windows 7 and Higher
        2. Installing Python on Mac OS X
        3. Installing Python on Ubuntu
      3. Once You’ve Installed Python
      4. Saving Your Python Programs
      5. What You Learned
    2. Chapter 2: Calculations and Variables
      1. Calculating with Python
        1. Python Operators
        2. The Order of Operations
      2. Variables Are Like Labels
      3. Using Variables
      4. What You Learned
    3. Chapter 3: Strings, Lists, Tuples, and Maps
      1. Strings
        1. Creating Strings
        2. Handling Problems with Strings
        3. Embedding Values in Strings
        4. Multiplying Strings
      2. Lists Are More Powerful Than Strings
        1. Adding Items to a List
        2. Removing Items from a List
        3. List Arithmetic
      3. Tuples
      4. Python Maps Won’t Help You Find Your Way
      5. What You Learned
      6. Programming Puzzles
        1. #1: Favorites
        2. #2: Counting Combatants
        3. #3: Greetings!
    4. Chapter 4: Drawing with Turtles
      1. Using Python’s turtle Module
        1. Creating a Canvas
        2. Moving the Turtle
      2. What You Learned
      3. Programming Puzzles
        1. #1: A Rectangle
        2. #2: A Triangle
        3. #3: A Box Without Corners
    5. Chapter 5: Asking Questions with if and else
      1. if Statements
        1. A Block Is a Group of Programming Statements
        2. Conditions Help Us Compare Things
      2. if-then-else Statements
      3. if and elif Statements
      4. Combining Conditions
      5. Variables with No Value—None
      6. The Difference Between Strings and Numbers
      7. What You Learned
      8. Programming Puzzles
        1. #1: Are You Rich?
        2. #2: Twinkies!
        3. #3: Just the Right Number
        4. #4: I Can Fight Those Ninjas
    6. Chapter 6: Going Loopy
      1. Using for Loops
      2. While We’re Talking About Looping...
      3. What You Learned
      4. Programming Puzzles
        1. #1: The Hello Loop
        2. #2: Even Numbers
        3. #3: My Five Favorite Ingredients
        4. #4: Your Weight on the Moon
    7. Chapter 7: Recycling Your Code with Functions and Modules
      1. Using Functions
        1. Parts of a Function
        2. Variables and Scope
      2. Using Modules
      3. What You Learned
      4. Programming Puzzles
        1. #1: Basic Moon Weight Function
        2. #2: Moon Weight Function and Years
        3. #3: Moon Weight Program
    8. Chapter 8: How to Use Classes and Objects
      1. Breaking Things into Classes
        1. Children and Parents
        2. Adding Objects to Classes
        3. Defining Functions of Classes
        4. Adding Class Characteristics as Functions
        5. Why Use Classes and Objects?
        6. Objects and Classes in Pictures
      2. Other Useful Features of Objects and Classes
        1. Inherited Functions
        2. Functions Calling Other Functions
      3. Initializing an Object
      4. What You Learned
      5. Programming Puzzles
        1. #1: The Giraffe Shuffle
        2. #2: Turtle Pitchfork
    9. Chapter 9: Python’s Built-in Functions
      1. Using Built-in Functions
        1. The abs Function
        2. The bool Function
        3. The dir Function
        4. The eval Function
        5. The exec Function
        6. The float Function
        7. The int Function
        8. The len Function
        9. The max and min Functions
        10. The range Function
        11. The sum Function
      2. Working with Files
        1. Creating a Test File
        2. Opening a File in Python
        3. Writing to Files
      3. What You Learned
      4. Programming Puzzles
        1. #1: Mystery Code
        2. #2: A Hidden Message
        3. #3: Copying a File
    10. Chapter 10: Useful Python Modules
      1. Making Copies with the copy Module
      2. Keeping Track of Keywords with the keyword Module
      3. Getting Random Numbers with the random Module
        1. Using randint to Pick a Random Number
        2. Using choice to Pick a Random Item from a List
        3. Using shuffle to Shuffle a List
      4. Controlling the Shell with the sys Module
        1. Exiting the Shell with the exit function
        2. Reading with the stdin Object
        3. Writing with the stdout Object
        4. Which Version of Python Am I Using?
      5. Doing Time with the time Module
        1. Converting a Date with asctime
        2. Getting the Date and Time with localtime
        3. Taking Some Time Off with sleep
      6. Using the pickle Module to Save Information
      7. What You Learned
      8. Programming Puzzles
        1. #1: Copied Cars
        2. #2: Pickled Favorites
    11. Chapter 11: More Turtle Graphics
      1. Starting with the Basic Square
      2. Drawing Stars
      3. Drawing a Car
      4. Coloring Things In
        1. A Function to Draw a Filled Circle
        2. Creating Pure Black and White
      5. A Square-Drawing Function
      6. Drawing Filled Squares
      7. Drawing Filled Stars
      8. What You Learned
      9. Programming Puzzles
        1. #1: Drawing an Octagon
        2. #2: Drawing a Filled Octagon
        3. #3: Another Star-Drawing Function
    12. Chapter 12: Using Tkinter for Better Graphics
      1. Creating a Clickable Button
      2. Using Named Parameters
      3. Creating a Canvas for Drawing
      4. Drawing Lines
      5. Drawing Boxes
        1. Drawing a Lot of Rectangles
        2. Setting the Color
      6. Drawing Arcs
      7. Drawing Polygons
      8. Displaying Text
      9. Displaying Images
      10. Creating Basic Animation
      11. Making an Object React to Something
      12. More Ways to Use the Identifier
      13. What You Learned
      14. Programming Puzzles
        1. #1: Fill the Screen with Triangles
        2. #2: The Moving Triangle
        3. #3: The Moving Photo
  13. Part II: Bounce!
    1. Chapter 13: Beginning Your First Game: Bounce!
      1. Whack the Bouncing Ball
      2. Creating the Game Canvas
      3. Creating the Ball Class
      4. Adding Some Action
        1. Making the Ball Move
        2. Making the Ball Bounce
        3. Changing the Ball’s Starting Direction
      5. What You Learned
    2. Chapter 14: Finishing Your First Game: Bounce!
      1. Adding the Paddle
        1. Making the Paddle Move
        2. Finding Out When the Ball Hits the Paddle
      2. Adding an Element of Chance
      3. What You Learned
      4. Programming Puzzles
        1. #1: Delay the Game Start
        2. #2: A Proper “Game Over”
        3. #3: Accelerate the Ball
        4. #4: Record the Player’s Score
  14. Part III: Mr. Stick Man Races for the Exit
    1. Chapter 15: Creating Graphics for the Mr. Stick Man Game
      1. Mr. Stick Man Game Plan
      2. Getting GIMP
      3. Creating the Game Elements
        1. Preparing a Transparent Image
        2. Drawing Mr. Stick Man
        3. Drawing the Platforms
        4. Drawing the Door
        5. Drawing the Background
        6. Transparency
      4. What You Learned
    2. Chapter 16: Developing the Mr. Stick Man Game
      1. Creating the Game Class
        1. Setting the Window Title and Creating the Canvas
        2. Finishing the __init__ Function
        3. Creating the mainloop Function
      2. Creating the Coords Class
      3. Checking for Collisions
        1. Sprites Colliding Horizontally
        2. Sprites Colliding Vertically
        3. Putting It All Together: Our Final Collision-Detection Code
      4. Creating the Sprite Class
      5. Adding the Platforms
        1. Adding a Platform Object
        2. Adding a Bunch of Platforms
      6. What You Learned
      7. Programming Puzzles
        1. #1: Checkerboard
        2. #2: Two-Image Checkerboard
        3. #3: Bookshelf and Lamp
    3. Chapter 17: Creating Mr. Stick Man
      1. Initializing the Stick Figure
        1. Loading the Stick Figure Images
        2. Setting Up Variables
        3. Binding to Keys
      2. Turning the Stick Figure Left and Right
      3. Making the Stick Figure Jump
      4. What We Have So Far
      5. What You Learned
    4. Chapter 18: Completing the Mr. Stick Man Game
      1. Animating the Stick Figure
        1. Creating the Animate Function
        2. Getting the Stick Figure’s Position
        3. Making the Stick Figure Move
      2. Testing Our Stick Figure Sprite
      3. The Door!
        1. Creating the DoorSprite Class
        2. Detecting the Door
        3. Adding the Door Object
      4. The Final Game
      5. What You Learned
      6. Programming Puzzles
        1. #1: “You Win!”
        2. #2: Animating the Door
        3. #3: Moving Platforms
  15. Afterword: Where to go From Here
    1. Games and Graphics Programming
      1. PyGame
    2. Programming Languages
      1. Java
      2. C/C++
      3. C#
      4. PHP
      5. Objective-C
      6. Perl
      7. Ruby
      8. JavaScript
    3. Final Words
  16. Appendix: Python Keywords
  17. Glossary
  18. Index
  19. Updates

Product information

  • Title: Python for Kids
  • Author(s): Jason R. Briggs
  • Release date: December 2012
  • Publisher(s): No Starch Press
  • ISBN: 9781593274078