O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Python Projects for Kids

Book Description

Unleash Python and take your small readers on an adventurous ride through the world of programming

About This Book

  • Learn to start using Python for some simple programming tasks such as doing easy mathematical calculations.
  • Use logic and control loops to build a nice interesting game.
  • Get to grips with working with data and, once you're comfortable with that, you'll be introduced to Pygame, which will help you wrap up the book with a cool game.

Who This Book Is For

This book is for kids (aged 10 and over). This is book is intended for absolute beginners who lack any knowledge of computing or programming languages and want to get started in the world of programming.

What You Will Learn

  • Start fiddling with Python's variables, build functions and interact with users
  • Build your own calculator using the Math Library
  • Train Python to make logical decisions
  • Work with moving 2D objects on-screen
  • Understand the Pygame Library and build your very own game!
  • Write a cool program to manage inventories in your backpack

In Detail

Kids are always the most fast-paced and enthusiastic learners, and are naturally willing to build stuff that looks like magic at the end (when it works!). Programming can be one such magic. Being able to write a program that works helps them feel they've really achieved something. Kids today are very tech-savvy and cannot wait to enter the fast-paced digital world.

Because Python is one of the most popular languages and has a syntax that is quite simple to understand, even kids are eager to use it as a stepping stone to learning programming languages.

This book will cover projects that are simple and fun, and teach kids how to write Python code that works.

The book will teach the basics of Python programming, installation, and so on and then will move on to projects. A total of three projects, with each and every step explained carefully, without any assumption of previous experience.

Style and approach

The book will take a light approach in guiding the little readers through the world of Python. The main idea is to teach by example and let the readers have as much exercises to do, so that they learn faster and can apply their own ideas to the existing examples. The book should get them thinking, by the end, on where they can go next with such a powerful tool at their disposal.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Python Projects for Kids
    1. Table of Contents
    2. Python Projects for Kids
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Welcome! Let's Get Started
      1. Python projects for you
        1. What can you do with Python?
        2. Why you should learn Python
      2. The prerequisites of Python
        1. Setting up your computer
          1. For Mac and Ubuntu Linux users
          2. Python 2.7
            1. Terminal – the command line and the Python shell
            2. Text editor
          3. For Windows users
            1. Command prompt
            2. Text editor
      3. Write and run your first program in the command line
      4. Make yourself a work folder
      5. A quick task for you
      6. Summary
    9. 2. Variables, Functions, and Users
      1. Variables
        1. Naming variables – conventions to follow
        2. What can variables remember?
          1. Strings
          2. Integers
          3. Floating point numbers (floats)
        3. Combining strings, integers, and floats
      2. Functions
        1. Built-in functions
        2. Parts of a function
      3. Users interacting with your program
      4. Using the text editor and the command line
      5. Build your own function – name()
        1. Set up your project file
        2. Begin your project
        3. Writing code
        4. Running your program
      6. Going the extra mile
      7. A quick task for you
      8. Summary
    10. 3. Calculate This!
      1. The calculator
      2. Basic functions
      3. Operations on two numbers
        1. Convert data into numbers – int() and float()
          1. Floating point to whole number conversion
          2. Whole number to floating point conversion
          3. Text strings fail in int() and float()
          4. Creating our first calculator file
      4. New functions – subtraction, multiplication, and division
        1. Subtraction
        2. Multiplication
        3. Division
      5. Finding a remainder – modulo
      6. Running your program
      7. A quick task for you
      8. Summary
    11. 4. Making Decisions – Python Control Flows
      1. Is it equal, not equal, or something else?
      2. Conditional statements – if, elif, else
        1. Getting better input
        2. if
        3. elif
        4. else
      3. Loops
        1. while
          1. Global variables and the quit() function
          2. Using the quit() function
          3. Using the while loop to control the program
        2. for
          1. Bonus – count_to_ten() function
      4. A quick task for you
      5. Summary
    12. 5. Loops and Logic
      1. Higher or Lower
        1. Game file set up
        2. Importing libraries
        3. Setting and initializing global variables
        4. What is a Boolean?
        5. Building the easy version
          1. Compare numbers
          2. play_again()
        6. Start, stop, play again
          1. start_game()
          2. play_again()
          3. Play testing
        7. Building the hard version
          1. Comparing numbers – the hard version
          2. Play test the whole program!
      2. A quick task for you
      3. Summary
    13. 6. Working with Data – Lists and Dictionaries
      1. Lists
        1. Parts of a list
        2. Working with a list
        3. Changing the list – adding and removing information
          1. Adding items to the list
          2. Removing items from the list
        4. Lists and loops
      2. Dictionaries
        1. Key/value pairs in dictionaries
        2. Changing the dictionary – adding and removing information
          1. Adding items to the dictionary
        3. Changing the value of an existing item
          1. Removing items from the dictionary
      3. List or dictionary
      4. A quick task for you
      5. Summary
    14. 7. What's in Your Backpack?
      1. Setting up our coding environment
      2. Planning to program your game
      3. Skills needed to make a program
      4. Score, play again, or quit?
      5. Getting and storing player information
        1. Making a players list
        2. Player profiles
        3. Player profiles – how do they work?
        4. Add players to profile
      6. Adding items to the virtual backpack
      7. Limiting items in a virtual backpack
      8. Testing your code so far
      9. A game loop
      10. Bringing back the while loop
      11. Comparing guesses with backpack items
      12. Keeping score
      13. Ending the game
      14. Testing your game
      15. A quick task for you
      16. Summary
    15. 8. pygame
      1. What is pygame?
      2. Installing pygame
        1. Installing pygame – Windows
        2. Installing pygame – Mac
          1. Installing Xcode
          2. Installing Homebrew
            1. Installing programs with homebrew
        3. Installing pygame – Ubuntu Linux
        4. Installing pygame – Raspberry Pi
      3. pygame
        1. Initializing pygame
        2. Setting up the game screen – size
        3. Setting up the game screen – color
        4. Making stationary objects
          1. while loop – viewing the screen
          2. Making more shapes
            1. Rectangle
            2. Ellipse
          3. Experimenting with shapes
          4. More advanced shapes
        5. Making moving objects
          1. Moving objects with the keyboard
      4. A quick task for you
      5. Summary
    16. 9. Tiny Tennis
      1. Introduction to game programming principles
      2. The game plan
      3. Creating an outline of game parts
      4. Section 1 – imports, globals, and drawings
        1. Importing libraries
        2. Introducing globals
        3. Defining a color
        4. Adjusting the screen size
        5. Drawing the screen
        6. Creating screen labels
        7. Ball – the starting location
        8. Ball – setting the speed and direction
        9. Ball – setting the size
        10. Paddles – starting location and size
      5. Initializing the score
      6. Testing section 1
      7. Section 2 – moving the paddles
        1. Pre-loop actions
        2. Creating the while loop
        3. Moving the paddles – keyboard events
        4. Exiting the game – escape key
        5. Paddle control – player 1
        6. Paddle control – player 2
      8. The increase and decrease value (-= and +=)
      9. Testing section 2
      10. Section 3 – moving the ball
        1. Moving the ball – updating the location
        2. Collision detection
          1. Collision of the ball with the top and the bottom of the screen
          2. Collision of the paddle with the top and the bottom of screen
          3. Collision of the ball with the paddles
      11. Testing – section 3
      12. Section 4 – draw screen and track the score
        1. The render screen – show what's happened
        2. Displaying player scores
      13. Ending the program
      14. Play Tiny Tennis!
      15. Summary
    17. 10. Keep Coding!
      1. What we learned and your next steps
      2. Classes and objects – very important next steps!
      3. More fun with games
      4. Adding music to games
      5. Adding graphics to games
      6. Remake or design games
      7. Other games
        1. PB-Ball
        2. Snake
      8. Other uses of Python
        1. SciPy
        2. iPython
        3. MatPlotLib
        4. Raspberry Pi
      9. Coding challenges
      10. Summary
    18. A. Quick Task Answers
      1. Chapter 1, Welcome! Let's Get Started
      2. Chapter 2, Variables, Functions, and Users
      3. Chapter 3, Calculate This!
      4. Chapter 4, Making Decisions – Python Control Flows
      5. Chapter 5, Loops and Logic
      6. Chapter 6, Working with Data – Lists and Dictionaries
      7. Chapter 7, What's in Your Backpack?
      8. Chapter 8, pygame
    19. Index