Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Teach Your Kids to Code: A Parent-Friendly Guide to Python Programming
Dedication
Advance Praise for Teach Your Kids to Code
About the Author
About the Illustrator
About the Technical Reviewer
Acknowledgments
Introduction: What Is Coding and Why Is It Good for Your Kids?
Why Should Kids Learn to Code?
Coding Is Fun
Coding Is a Valuable Job Skill
Where Can Kids Learn to Code?
How to Use This Book
Explore!
Do It Together!
Online Resources
Coding = Solving Problems
1. Python Basics: Get to Know Your Environment
Getting Started with Python
1. Download Python
2. Install Python
3. Test Python with a Program
Writing Programs in Python
Running Programs in Python
What You Learned
2. Turtle Graphics: Drawing with Python
Our First Turtle Program
SquareSpiral1.py
How It Works
What Happens
Turtle on a Roll
SquareSpiral2.py
Turtle Roundup
CircleSpiral1.py
Adding a Touch of Color
SquareSpiral3.py
A Four-Color Spiral
ColorSquareSpiral.py
Changing Background Colors
ColorCircleSpiral.py
One Variable to Rule Them All
ColorSpiral.py
What You Learned
3. Numbers and Variables: Python Does the Math
Variables: Where We Keep Our Stuff
ThankYou.py
Numbers and Math in Python
Python Numbers
Python Operators
Doing Math in the Python Shell
Syntax Errors: What Did You Say?
Variables in the Python Shell
Programming with Operators: A Pizza Calculator
AtlantaPizza.py
Strings: The Real Characters in Python
SayMyName.py
Improving Our Color Spiral With Strings
SpiralMyName.py
Lists: Keeping It All Together
ColorSpiralInput.py
Python Does Your Homework
MathHomework.py
What You Learned
4. Loops Are Fun (You Can Say That Again)
Rosette.py
Building Your Own for Loops
Using a for Loop to Make a Rosette with Four Circles
Rosette4.py
Modifying Our for Loop to Make a Rosette with Six Circles
Rosette6.py
Improving Our Rosette Program with User Input
RosetteGoneWild.py
Game Loops and while Loops
SayOurNames.py
The Family Spiral
SpiralFamily.py
Putting It All Together: Spiral Goes Viral
ViralSpiral.py
What You Learned
5. Conditions (What If?)
If Statements
IfSpiral.py
Meet the Booleans
Comparison Operators
You’re Not Old Enough!
OldEnough.py
Else Statements
OldEnoughOrElse.py
Polygons or Rosettes
PolygonOrRosette.py
Even or Odd?
RosettesAndPolygons.py
Elif Statements
WhatsMyGrade.py
Complex Conditions: If, and, or, not
WhatToWear.py
Secret Messages
Messin’ with Strings
The Value of Character(s)
Our Encoder/Decoder Program
EncoderDecoder.py
What You Learned
6. Random Fun and Games: Go Ahead, Take a Chance!
A Guessing Game
GuessingGame.py
Colorful Random Spirals
Pick a Color, Any Color
Getting Coordinated
Cartesian Coordinates
Setting a Random Turtle Position
How Big Is Our Canvas?
Putting It All Together
RandomSpirals.py
Rock-Paper-Scissors
RockPaperScissors.py
Pick a Card, Any Card
Stacking the Deck
Dealing Cards
Counting Cards
Finding an Item in a List
Which Card is Higher?
Keeping It Going
Putting It All Together
HighCard.py
Roll the Dice: Creating a Yahtzee-Style Game
Setting Up the Game
Sorting the Dice
Testing the Dice
Putting It All Together
FiveDice.py
Kaleidoscope
Kaleidoscope.py
What You Learned
7. Functions: There’s a Name for That
Putting Things Together with Functions
Defining Random_Spiral()
Calling Random_Spiral()
RandomSpiralsFunction.py
Parameters: Feeding Your Function
Smileys at Random Locations
Drawing a head
Drawing eyes
Drawing a mouth
Defining and Calling Draw_Smiley()
Putting it all together
RandomSmileys.py
Return: It’s What You Give Back That Counts
Returning a Value from a Function
Using Return Values in a Program
PingPongCalculator.py
A Touch of Interaction
Handling Events: TurtleDraw
TurtleDraw.py
TurtleDrawMax.py
Listening for Keyboard Events: ArrowDraw
ArrowDraw.py
Handling Events with Parameters: Clickspiral
ClickSpiral.py
Taking It One Step Further: Clickandsmile
ClickAndSmile.py
ClickKaleidoscope
The Draw_Kaleido() Function
The Draw_Spiral() Function
Putting It All Together
ClickKaleidoscope.py
What You Learned
8. Timers and Animation: What Would Disney Do?
Getting All GUI with Pygame
Drawing a Dot with Pygame
ShowDot.py
What’s New in Pygame
The Parts of a Game
Setting Up
Creating a Game Loop
Exiting the Program
Putting It All Together
ShowPic.py
Timing It Just Right: Move and Bounce
Moving a Smiley
Animating a Smiley with the Clock Class
SmileyMove.py
Bouncing a Smiley Off a Wall
Hitting the Wall
Changing Direction
Putting It All Together
SmileyBounce1.py
Bouncing a Smiley Off Four Walls
Horizontal and Vertical Speed
Hitting Four Walls
Putting It All Together
SmileyBounce2.py
What You Learned
9. User Interaction: Get into the Game
Adding Interaction: Click and Drag
Clicking for Dots
Setup
Game Loop: Handling Mouse Clicks
Putting It All Together
ClickDots.py
Dragging to Paint
Setup
Game Loop: Handling Mouse Presses and Releases
Putting It All Together
DragDots.py
Advanced Interaction: Smiley Explosion
Smiley Sprites
More on Classes and Objects
Using classes to Build our app
Setting Up Sprites
Updating Sprites
Bigger and Smaller Smileys
Putting It All Together
SmileyExplosion.py
SmileyPop, Version 1.0
Detecting Collisions and Removing Sprites
Putting It All Together
SmileyPop.py
What You Learned
10. Game Programming: Coding for Fun
Building a Game Skeleton: Smiley Pong, Version 1.0
Drawing a Board and Game Pieces
Keeping Score
Subtracting a Life
Hitting the Ball with the Paddle
Adding a Point
Showing the Score
Putting It All Together
SmileyPong1.py
Adding Difficulty and Ending the Game: Smiley Pong, Version 2.0
Game Over
Play Again
Faster and Faster
Putting It All Together
SmileyPong2.py
Adding More Features: SmileyPop V2.0
Adding Sound with Pygame
Tracking and Displaying Player Progress
Smileys Created and Popped
Percentage of Smileys Popped
Putting It All Together
SmileyPop2.py
What You Learned
A. Python Setup for Windows, Mac, and Linux
Python for Windows
Download the Installer
Run the Installer
Try Out Python
Python for Mac
Download the Installer
Run the Installer
Try Out Python
Python for Linux
B. Pygame Setup for Windows, Mac, and Linux
Pygame for Windows
Pygame for Mac
Python 2.7 and Pygame 1.9.2
Pygame for Linux
Pygame for Python 2
C. Building Your Own Modules
Building the colorspiral Module
colorspiral.py
Using The Colorspiral Module
MultiSpiral.py
Reusing the Colorspiral Module
SuperSpiral.py
Additional Resources
D. Glossary
E. Updates
Index
Copyright
← Prev
Back
Next →
← Prev
Back
Next →