logo资料库

Teach Your Kids to Code: A Parent- Friendly Guide to Python Prog....pdf

第1页 / 共344页
第2页 / 共344页
第3页 / 共344页
第4页 / 共344页
第5页 / 共344页
第6页 / 共344页
第7页 / 共344页
第8页 / 共344页
资料共344页,剩余部分请下载后查看
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
Teach Your Kids to Code: A Parent- Friendly Guide to Python Programming Bryson Payne Published by No Starch Press
To Alex and Max, my two favorite coders
Advance Praise for Teach Your Kids to Code “The text is clear, the graphics are engaging, and the apps are awesome. This is the programming guide for parents and kids to enjoy together.” — Aaron Walker, Cybersecurity Expert, NASA “The energy and excitement Bryson brings to teaching is captured perfectly in Teach Your Kids to Code, with colorful, captivating games and graphics that help develop real-world skills.” — Bindy Auvermann, Executive Director, Next Generation Youth Development, Inc. “Provides the building blocks of a great future in the rapidly changing world of technology.” — JoAnne Taylor, former Vice President, Global Telecommunications, IBM “The concepts in Teach Your Kids to Code can help any young person enhance their college prospects and expand their career opportunities, and Dr. Payne presents these skills through fun, challenging games and apps.” — Dr. Raj Sunderraman, Department Chair of Computer Science, Georgia State University “Every child on the planet should have this book, and so should every parent.” — James E. Daniel, Jr., Founder, App Studios, LLC “An innovative, motivating guide … Builds skills that can last a lifetime.” — Dr. Steven Burrell, Vice President for Information Technology & CIO, Georgia Southern University “The kind of book I wish I’d had as a kid.” — Scott Hand, Software Engineer, CareerBuilder “Dr. Bryson Payne is a computer scientist and professor of the highest caliber, and with Teach Your Kids to Code, he brings the power of computers within easy reach for readers young and old.” — Dr. Antonio Sanz Montemayor, Informatics Professor, Universidad Rey Juan Carlos, Spain “A brilliant combination of engaging, imaginative apps and valuable, lifelong skills.” — Ted Cunningham, author of The Power of Home “Teach Your Kids to Code and the logical thinking it introduces will help build the next generation of technology leaders.” — N. Dean Meyer, author and executive coach “This book can jump-start your child’s success in a high-tech world.” — Ken Coleman, leadership author and former radio host of The Ken Coleman Show “Dr. Payne set us on the path that led us to our dream jobs! With Teach Your Kids to Code, he’s providing parents and teachers everywhere the chance to do the same for the next generation of creative problem-solvers.” — Shah and Susan Rahman, Riot Games “Bryson helps people improve their lives with technology. His book does the same.” — Ash Mady, Technical Manager, RedHat, Inc. “Enjoyable and accessible to parents and children alike.” — Steve McLeod, Deputy CIO, University of North Georgia “Dr. Payne used robots, games, and fun programs to motivate me in college, and Teach Your Kids to Code extends that same passion for coding cool apps beyond the walls of the campus.” — Bobby Brown, Lead Developer, GetUWired
分享到:
收藏