Teach Your Kids to Code: A Parent-Friendly Guide to Python Programming
how to use this Book This book isn’t just for kids it’s for parents teachers students and adults who want to understand the basics of computer pro gramming both to have fun and to gain access to new jobs in the high-tech economy No matter what your age you can have a great time learning the basics of programming The best way to do this is to experiment and work together Explore Learning to program is exciting if you’re willing to try new things As you and your kids follow along with the programs in this book try changing numbers and text in the code to see what happens to the program Even if you break it you’ll learn something new by fixing it In the worst case all you have to do is retype the example from the book or open the last saved version that worked The point of learning to code is to try something new learn a new skill and solve problems in a new way Make sure your kids are playing around testing their code by changing something saving the pro gram running it seeing what happens and fixing any errors The point of learning to code is to try something new learn a new skill and solve problems in a new way Test your code by changing something saving the program running it seeing what happens and fixing errors if needed For example I wrote some code to make a colorful drawing Figure 2 and then went back changed some numbers here and there and tried running the program again This gave me another drawing that was completely different but just as amazing I went back again changed some other numbers and got yet another beau tiful unique drawing See what you can do just by playing around Figure 2 Three colorful spiral drawings I created by trying different values in a line of code in one program xxiv Introduction
do It together Experimenting with code is a great way to learn how programs work and it’s even more effective if you work with someone else Whether you’re teaching a child or student or studying for yourself it’s not just more fun to play with code together it’s also more effective For example in the Suzuki Method of music instruction par ents attend lessons with their child and even study ahead so they can help their child between lessons Starting early is another hallmark of the Suzuki Method kids can start formal study by the age of three or four I began introducing my two sons to programming when they were two and four and I encouraged them to have fun by changing small parts of each program like the colors shapes and sizes of shapes I learned to program at the age of 13 by typing program examples from books and then modifying them to make them do something new Now in the computer science courses I teach I often give students a program and encourage them to play around with the code to build something new If you’re using this book to teach yourself you can work with others by finding a friend to work through examples with you or by starting an after-school or community coding club see http coderdojo com or http www codecademy com afterschool for ideas and tips Coding is a team sport online resources All the program files for this book are available at http www nostarch com teachkids as well as sample solutions for the Programming Challenges and other informa tion Download the programs and experiment with them to learn even more Use the sample solutions if you get stumped Check it out What Is Coding and Why Is It Good for Your Kids xxv
Coding solving Problems Whether your child is 2 years old and learning to count or 22 and looking for a new challenge this book and the concepts it introduces are a great pathway to a rewarding inspiring pastime and better career opportunities People who can program and thus solve problems quickly and effectively are highly valued in today’s world and they get to do interesting fulfilling work Not all of the world’s problems can be solved with technology alone but technology can enable communication collaboration awareness and action at a scale and speed never before imagined If you can code you can solve problems Problem-solvers have the power to make the world a better place so start coding today xxvi Introduction
1 Python Basics Get to Know your environment Just about anything could have a computer in it a phone a car a watch a video game console an exercise machine a medical device industrial equipment a greeting card or a robot Computer pro gramming or coding is how we tell a computer to perform a task and understanding how to code puts the power of computers at your fingertips