Python Projects For Kids 1st Edition Ingrassellino Download PDF
Python Projects For Kids 1st Edition Ingrassellino Download PDF
com
https://textbookfull.com/product/python-projects-
for-kids-1st-edition-ingrassellino/
https://textbookfull.com/product/python-for-kids-a-playful-
introduction-to-programming-1st-edition-briggs/
textbookfull.com
https://textbookfull.com/product/python-projects-for-beginners-a-ten-
week-bootcamp-approach-to-python-programming-milliken/
textbookfull.com
Gardening for Kids Learn Grow and Get Messy with Fun STEAM
Projects 1st Edition Stone
https://textbookfull.com/product/gardening-for-kids-learn-grow-and-
get-messy-with-fun-steam-projects-1st-edition-stone/
textbookfull.com
https://textbookfull.com/product/cancer-genetics-and-therapeutics-
focus-on-phytochemicals-madhumita-roy/
textbookfull.com
An Office Grinch Romance 1st Edition Sharon Cummin
https://textbookfull.com/product/an-office-grinch-romance-1st-edition-
sharon-cummin/
textbookfull.com
https://textbookfull.com/product/sustainable-water-management-new-
perspectives-design-and-practices-1st-edition-kenichi-nakagami/
textbookfull.com
https://textbookfull.com/product/stewart-macaulay-selected-works-
david-campbell/
textbookfull.com
https://textbookfull.com/product/effective-police-supervision-study-
guide-larry-s-miller/
textbookfull.com
https://textbookfull.com/product/think-like-a-data-scientist-tackle-
the-data-science-process-step-by-step-1st-edition-brian-godsey/
textbookfull.com
Biodiversity Conservation and Phylogenetic Systematics
Preserving our evolutionary heritage in an extinction
crisis 1st Edition Roseli Pellens
https://textbookfull.com/product/biodiversity-conservation-and-
phylogenetic-systematics-preserving-our-evolutionary-heritage-in-an-
extinction-crisis-1st-edition-roseli-pellens/
textbookfull.com
Python Projects for Kids
Jessica Ingrassellino
BIRMINGHAM - MUMBAI
Python Projects for Kids
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78217-506-3
www.packtpub.com
Credits
Reviewer Proofreader
David Whale Safis Editing
Technical Editor
Rupali R. Shrawane
Copy Editor
Sonia Cheema
About the Author
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.
David Whale is a software developer who lives in Essex, UK. He started coding
as a schoolboy aged 11, inspired by his school's science technician to build his own
computer from a kit. These early experiments lead to some of his code being used in
a saleable educational word game when he was only 13.
David has been developing software professionally ever since, mainly writing
embedded software that provides intelligence inside electronic products, including
automated machinery, electric cars, mobile phones, energy meters, and wireless
doorbells.
These days, David runs his own software consultancy called Thinking Binaries,
and he spends about half of his time helping customers design software for new
electronic products, many of which use Python. The rest of the time, he volunteers
for The Institution of Engineering and Technology, running training courses for
teachers, designing and running workshops and clubs for school children, running
workshops and talks at meet-up events all round the UK, and generally being busy
with his Raspberry Pi, BBC micro:bit, and Arduino.
David was the technical editor of Adventures in Raspberry Pi, John Wiley & Sons, the
coauthor of Adventures in Minecraft, and he is a regular reviewer and editor
of technical books for a number of book publishers.
At www.PacktPub.com, you can also read a collection of free technical articles, sign
up for a range of free newsletters and receive exclusive discounts and offers on Packt
books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
Table of Contents
Preface vii
Chapter 1: Welcome! Let's Get Started 1
Python projects for you 1
What can you do with Python? 1
Why you should learn Python 2
The prerequisites of Python 2
Setting up your computer 3
For Mac and Ubuntu Linux users 3
Python 2.7 3
For Windows users 5
Write and run your first program in the command line 7
Make yourself a work folder 9
A quick task for you 10
Summary 11
Chapter 2: Variables, Functions, and Users 13
Variables 13
Naming variables – conventions to follow 14
What can variables remember? 15
Strings 15
Integers 16
Floating point numbers (floats) 17
Combining strings, integers, and floats 18
Functions 19
Built-in functions 19
Parts of a function 20
Users interacting with your program 22
Using the text editor and the command line 23
[i]
Table of Contents
[ ii ]
Table of Contents
[ iii ]
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Table of Contents
[ iv ]
Table of Contents
[v]
Table of Contents
[ vi ]
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.
Chapter 2, Variables, Functions, and Users, covers Python data types and functions,
as well as how to program Python to get information from the user, store that
information, and use it later.
Chapter 3, Calculate This!, uses Python to make a calculator that has multiple
mathematical functions. We also learn about working in our file structure and the
proper way to save code files.
Chapter 4, Making Decisions – Python Control Flows, covers the use of if, elif, and
else, as well as the use of for and while loops, in order to help create programs
that make decisions based on user actions.
[ vii ]
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.
[ viii ]
Preface
Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"Why don't you try giving the computer the name variable with your name and then
the height variable with your height?"
name()
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.
[ ix ]
Preface
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box.
5. Select the book for which you're looking to download the code files.
6. Choose from the drop-down menu where you purchased this book from.
7. Click on Code Download.
You can also download the code files by clicking on the Code Files button on the
book's webpage at the Packt Publishing website. This page can be accessed by entering
the book's name in the Search box. Please note that you need to be logged in to your
Packt account.
Once the file is downloaded, please make sure that you unzip or extract the folder
using the latest version of:
[x]
Preface
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.
[ xi ]
Welcome! Let's Get Started
If you've picked up this book, then you are taking your first step toward building
amazing projects using code. Some of you might want to make games, while others
might want to learn more about how all of your favorite websites and apps actually
work. If you follow the exercises in this book, you'll be able to do the following:
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.
It has also been used to build many small video games by people learning about
it as well as more advanced programmers. Finally, Python can be used to quickly
read and analyze millions of lines of data very quickly! By learning Python, you will
be prepared to build a variety of interesting projects, and you will gain the skills
necessary to learn other programming languages if you choose to do so.
[2]
Chapter 1
All of the code samples in this book are available for download on
the Packt Publishing website.
For the projects in this book, we will be using Python 2.7. While there are higher
versions than this (3.x), these versions do not work dependably with pygame on
Windows, Mac, or Ubuntu Linux as yet. However, this book will be written to
use conventions that work in both versions of Python so that projects are easily
completed on Raspberry Pi (which uses Python 3.x that's been specially configured
with pygame) with just a few modifications. These modifications will be duly noted.
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]
Welcome! Let's Get Started
• 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.
• The terminal also functions as a Python shell when a command is given to
run Python. We will learn about this later.
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.
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:
Use the official Python website for the latest releases for Windows
at https://www.python.org/downloads/release/
python-2711/.
With Windows, you need to figure out if you are running 32-bit or
64-bit so that you can download the correct version of Python. To
help you to determine which one is correct, visit
http://windows.microsoft.com/en-gb/windows/32-bit-
and-64-bit-windows#1TC=windows-7.
Download x86only if your computer is running 32-bit Windows.
Most users will download the x86-64 version of Python.
[5]
Welcome! Let's Get Started
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.
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]
Random documents with unrelated
content Scribd suggests to you:
[Transcription]
PATRIOTIC PROPOSALS—1791-92
‘So you tell me that I know not how to stay at home! but this
is a visit of pure friendship, for the duke likes very well to chat
with me, though he is so nervous as hardly to bear with
strangers. Yesterday Lord Clermont, who is very intimate with
him, came hither, but he was too much for the duke, and had he
not gone away this morning, the duchess would have hinted it
gently to him. What would you do with such nerves?
‘Last night, instead of reading a sermon or charge, I read to
the whole company (by the duke’s desire) your essays on the
place of corn and capital employed in the French husbandry, with
which he had been so pleased. Lord Clermont, who has lived
much in France, and though a man of pleasure, had inquired
much into the state of that country, was not more delighted than
surprised with them. “Well, then,” said the duke, “as you like
them so much and intend to buy the book, recommend it as
much as possible to your friends in the great world.” This he
engaged to do. His Lordship gave a pressing invitation for you
and I to pass two or three days with him; he fixed upon the
month of May, which will suit me, and, I hope, you.
‘As an inducement I was to tell you that he has marled four
hundred and fifty acres with a hundred and twenty loads an acre
—this is an object.
‘J Symonds.’
My reply:—
‘You, “the willing advocate of every feeling I excommunicate
from my bosom,” knew you had thrown so bitter a potion into
your letter that you could not (kind creature!) help a little
sweetening in the postscript; but must there in your sweets be
some alloy? Could you not conclude without falling foul of poor
Ceres?
‘Your letter, or rather your profession of faith, is one of the
worst political creeds I remember to have read; you see no merit
but beneath a diadem. In government a professed aristocrat, in
political economy a monopolist, who commends manufactures,
not as a market for the farmer, but for the much nobler purpose
of contributing to adorn your outside; and who can attain not
one better idea of the immortal plough than that of giving some
sustenance to your inside. But, by the way, is not that inside of
yours an equivoque? Do you mean your real or your
metaphorical inside, your ribs or your feelings? If you allude to
your brains, they are by your own account a wool-gathering. Do
you mean your heart, and that the philosophical contemplation
of so pure an engine as the plough is the sustenance of your
best emotions? How will that agree with the panegyrist of a
court and the satirist of a farm? Or is it that this inside of yours
is a mere bread and cheese cupboard, which, certes, the plough
can furnish? Or is it a magic lanthorn full of gay delusions,
lighted by tallow from the belly of a sheep? Till you have settled
these doubts, I know not which you prefer, manufactures for
improving your complection, or agriculture for farming your
heart. Nor must you wonder at such questions arising while you
use terms that leave one in doubt whether you mean your head
or your tail. I know something of the one; the other is a
metaphor. Though there is high treason against the plough in
almost every line of your letter, yet the words If I can I will are
not in the spirit that contains the Eleusinian mysteries; they
bring balm to my wounded feelings.’
CHAPTER X
THE BOARD OF AGRICULTURE, 1793
‘Dear Sir,—I have just seen in the True Briton of this morning
that the thanks of the association at the “Crown and Anchor”
were voted to you for your last publication, which, I assure you,
gives me great pleasure; at the same time it reminds me that I
have too long deferred mine, but which I now beg you will
accept. I like it very much, and think it is admirably well written,
and calculated to inform the ignorant and deluded of their real
danger. I should have told you so long ago, but waited to hear
the opinions of those from which I thought you would receive
more satisfaction; and I can now assure you that your pamphlet
is much liked by Lord Orford and several others of good
judgment. And I think you may, without flattery, consider
yourself as one of the means which has rescued this glorious
country from the destruction which was preparing for it.