Book Image

Python Projects for Kids

By : Jessica Ingrassellino
Book Image

Python Projects for Kids

By: Jessica Ingrassellino

Overview of this book

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.
Table of Contents (18 chapters)
Python Projects for Kids
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Section 4 – draw screen and track the score


So, we know that the ball bounces off the top and bottom of the screen as well as off the paddles. However, if the user misses the ball with the paddle, what happens to the ball? What happens to the player and their score?

In this section of the game, we use the location of the x coordinates to determine whether the ball is on the screen or it has gone past the paddles and is outside the screen. We use our if statement to tell the computer what to do. The x axis 0 coordinate is the left-most side of the screen. If the ball's x value is less than 0, then the player on the other side (player 2) has scored a point because player 1 failed to block the ball. If you read the lines of code, you will notice that we reset the ball_x and ball_y coordinates to the center of the screen so that a new game can start. Copy the next four lines of code to place this logic into the game:

    if ball_x <= 0:
      player2_score += 1
      ball_x = int(screen_width...