Python Projects For Kids - Sample Chapter
Python Projects For Kids - Sample Chapter
$ 34.99 US
22.99 UK
P U B L I S H I N G
pl
C o m m u n i t y
Jessica Ingrassellino
Sa
m
This book will cover projects that are simple and fun,
and teach kids how to write Python code that works.
Python Projects
for Kids
ee
D i s t i l l e d
E x p e r i e n c e
Jessica Ingrassellino
She received her EdD from Teachers College, Columbia University for music education
with an emphasis on assessment.
Jessica is currently employed as the lead software engineer in testing at Bitly, New
York City. She transitioned from a teaching career of 10 years to a technology career
through a balance of freelance work and social media exposure. Jessica's current
work focuses on using Python to develop automated testing tools. She is an ASTQB
certified quality assurance engineer with experience in testing web, mobile, and
backend applications.
In addition to working at Bitly, Jessica remains committed to education and
has founded http://www.teachcode.org/, a nonprofit that teaches computer
programming skills to teachers and students in urban or underserved populations
through Python and 2D game programming. This new initiative will give teachers
the support they need through a standards-referenced curriculum, student-engaging
activities, and access to experts in the field of technology.
Preface
As you can guess from the title, this book is designed to teach the basic concepts of
Python to kids. This book uses several mini projects so that kids can learn how to
solve problems using Python.
Python has grown to become a very popular language for programming web apps,
analyzing data, and teaching people how to write code. Python is known for being a
simple language to use because it is read much like natural languages, yet it is able
to do data analysis very quickly, making it a great language to create websites that
handle a lot of data. Another nice thing about Python that makes it fun to use is that
people have been working on game libraries, such as pygame, so that people can
create graphics programs with Python. The use of simple graphics to make short
games is a fun way to learn programming constructs and is especially good for
visual learners.
Preface
Chapter 5, Loops and Logic, builds upon what we have learned in the previous chapters
and allows us to build a number guessing game. We will build easy and difficult
versions of the game.
Chapter 6, Working with Data Lists and Dictionaries, explains how to use lists
and dictionaries to store data. The differences between lists and dictionaries are
explained, and we spend time building small lists and dictionaries as well.
Chapter 7, What's in Your Backpack?, allows us to use functions, loops, logic, lists and
dictionaries to build a different kind of guessing game. We will also learn about
nesting dictionaries and lists.
Chapter 8, pygame, talks about a popular graphical library that is used in Python
to make small games. We will learn the fundamental aspects of this library and
experiment with some code.
Chapter 9, Tiny Tennis, this game is a clone of a popular game. We will re-create the
game using all of the skills that we have learned throughout the book. This is the
major project of the book.
Chapter 10, Keep Coding!, shows you all the opportunities that will arise once you read
this book.
Appendix, Quick Task Answers, has the answers to all the quick task questions within
the chapters.
So, what will it take to learn Python? If you have never programmed, you will
probably want to follow each lesson in order so that you can build the skills you
need to make a game or another kind of computer program. The final project in
this book will be a game. If you have some other programming experience, such as
making modifications to your computer games, using programs such as Scratch or
Logo or trying some of the free programming classes on the Internet, then you might
decide to skim this book first to see what you already know. It is still recommended
that you follow the contents of this book in the order they are presented, as each
project builds on the projects that were explained in the previous chapter.
Along with an Internet connection, you will also need a web browser, such as
Firefox, Safari, Chrome, or Internet Explorer, which will allow you to visit the
Python documentation pages.
[2]
Chapter 1
All of the code samples in this book are available for download on
the Packt Publishing website.
Python 2.7
At the time of writing, Mac OS X El Capitan comes with Python 2.7 preinstalled,
so nothing extra needs to be done at this point.
Ubuntu Linux 15.10 has Python 2.7.10 installed by default, so users of this latest
(as of writing this) version of Linux also need to do nothing extra at this point.
[3]
Ubuntu users can search for terminal on their desktops, and the program
will show up in their Start menu. When you click on the terminal, you will
see a small, black window on your screen.
Text editor
A text editor is a helpful tool for writing and editing Python programs. The terminal
is a nice place to test snippets of Python code, but when we want to edit and save the
code in order to use it over again, we will need a text editor. Although both Mac
and Linux systems come with a text editor, there are some very nice, free editors
that have good features. jEdit is one of these editors.
For Mac and Linux, go to http://www.jedit.org/ and download
jEdit. Follow the installation instructions.
To successfully complete all of the exercises in this book, you will often need to keep
both the terminal and text editor open at the same time on your screen.
[4]
Chapter 1
This is what the text editor application, jEdit, looks like in Mac and Linux:
[5]
2. Choose the executable installer, and you will see the download progress.
3. When the download is complete, you will see a prompt to run Python.
Click on Run.
4. An install prompt will come up, and when it does, look at the bottom of the
window and click on the box next to Add Python 2.x to Path. Then, select
Install Now.
5. Follow the installation instructions. Each step may take a few minutes. Once
the installation is done, you will have an icon for Python 2.7.11, which you
can find by searching for Python in the Windows search bar. This will open a
special Python shell from where you can run and test the Python code.
Command prompt
In Windows 10, you will see a terminal called the command prompt. The command
prompt is significantly different in Windows than it is on Mac or Linux.
To find the command prompt in Windows 10, perform these steps:
1. Go to the search bar at the bottom of the screen and search for cmd
or command.
2. When you do, you will see the command prompt desktop app appear.
Click on this app to open the command prompt, which looks like this:
Text editor
In Windows, Notepad is the default text editor. However, Notepad++ is a much
better substitute.
[6]
Chapter 1
In the Mac or Ubuntu terminal, your resulting Python shell will look like this:
>>>
In Windows, type Python in the search bar at the bottom of the page. Then,
select Python 2.7.11 from your apps. You will also have a Python shell open:
>>>
Once you see this symbol, your computer is now ready to work with the Python
code. In your terminal or IDLE, type the following:
>>>print("Hello, world!")
[7]
Once you have typed this, double-check to make sure that all of the spaces are
exactly as they've been written. In Python, every space actually matters. Every
punctuation mark matters. Once you have checked your code, hit Enter.
What is your result or the output of your code? If the output looks like the
following image, then great! You typed all of your code properly so the computer
will understand what you want it to do. The expected output will be similar to what
is shown here:
For Windows users, the output window will look like this:
So, if your output does not look like the preceding code, you need to figure out
what's wrong with it. Here are some of the reasons for this:
world!'?
Did you forget to use the ''single quotation marks for Hello, world!?
If you still have a problem, compare your code to the sample input code and fix any
mistakes. Then, try to run the code again.
[8]
Chapter 1
[9]
[ 10 ]
Chapter 1
Summary
If you are reading this, it is because you have made it through some of the tricky
work of getting ready to learn to program projects with Python. Congratulations!
Setting it up is always tough. Hopefully, you learned a bit more about the tools on
your computer, such as the text editor and terminal that every programmer uses
to do their daily work. Also, you learned about the Python print() function, and
you should now be able to print out messages in your Python shell. The fun is just
beginning as we have so much more to learn!
In the next chapter, you will learn about the building blocks of Python programs.
We'll start with variables and learn about all the different kinds of information we
can put in them. Then, we will build some functions that put these variables together
and help us make blocks of code that have special jobs. Finally, we will even learn
how to make a computer ask a user questions and store their answers so that our
programs can become interactive!
[ 11 ]
www.PacktPub.com
Stay Connected: