售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Python Projects for Kids
Table of Contents
Python Projects for Kids
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Welcome! Let's Get Started
Python projects for you
What can you do with Python?
Why you should learn Python
The prerequisites of Python
Setting up your computer
For Mac and Ubuntu Linux users
Python 2.7
Terminal – the command line and the Python shell
Text editor
For Windows users
Command prompt
Text editor
Write and run your first program in the command line
Make yourself a work folder
A quick task for you
Summary
2. Variables, Functions, and Users
Variables
Naming variables – conventions to follow
What can variables remember?
Strings
Integers
Floating point numbers (floats)
Combining strings, integers, and floats
Functions
Built-in functions
Parts of a function
Users interacting with your program
Using the text editor and the command line
Build your own function – name()
Set up your project file
Begin your project
Writing code
Running your program
Going the extra mile
A quick task for you
Summary
3. Calculate This!
The calculator
Basic functions
Operations on two numbers
Convert data into numbers – int() and float()
Floating point to whole number conversion
Whole number to floating point conversion
Text strings fail in int() and float()
Creating our first calculator file
New functions – subtraction, multiplication, and division
Subtraction
Multiplication
Division
Finding a remainder – modulo
Running your program
A quick task for you
Summary
4. Making Decisions – Python Control Flows
Is it equal, not equal, or something else?
Conditional statements – if, elif, else
Getting better input
if
elif
else
Loops
while
Global variables and the quit() function
Using the quit() function
Using the while loop to control the program
for
Bonus – count_to_ten() function
A quick task for you
Summary
5. Loops and Logic
Higher or Lower
Game file set up
Importing libraries
Setting and initializing global variables
What is a Boolean?
Building the easy version
Compare numbers
play_again()
Start, stop, play again
start_game()
play_again()
Play testing
Building the hard version
Comparing numbers – the hard version
Play test the whole program!
A quick task for you
Summary
6. Working with Data – Lists and Dictionaries
Lists
Parts of a list
Working with a list
Changing the list – adding and removing information
Adding items to the list
Removing items from the list
Lists and loops
Dictionaries
Key/value pairs in dictionaries
Changing the dictionary – adding and removing information
Adding items to the dictionary
Changing the value of an existing item
Removing items from the dictionary
List or dictionary
A quick task for you
Summary
7. What's in Your Backpack?
Setting up our coding environment
Planning to program your game
Skills needed to make a program
Score, play again, or quit?
Getting and storing player information
Making a players list
Player profiles
Player profiles – how do they work?
Add players to profile
Adding items to the virtual backpack
Limiting items in a virtual backpack
Testing your code so far
A game loop
Bringing back the while loop
Comparing guesses with backpack items
Keeping score
Ending the game
Testing your game
A quick task for you
Summary
8. pygame
What is pygame?
Installing pygame
Installing pygame – Windows
Installing pygame – Mac
Installing Xcode
Installing Homebrew
Installing programs with homebrew
Installing pygame – Ubuntu Linux
Installing pygame – Raspberry Pi
pygame
Initializing pygame
Setting up the game screen – size
Setting up the game screen – color
Making stationary objects
while loop – viewing the screen
Making more shapes
Rectangle
Ellipse
Experimenting with shapes
More advanced shapes
Making moving objects
Moving objects with the keyboard
A quick task for you
Summary
9. Tiny Tennis
Introduction to game programming principles
The game plan
Creating an outline of game parts
Section 1 – imports, globals, and drawings
Importing libraries
Introducing globals
Defining a color
Adjusting the screen size
Drawing the screen
Creating screen labels
Ball – the starting location
Ball – setting the speed and direction
Ball – setting the size
Paddles – starting location and size
Initializing the score
Testing section 1
Section 2 – moving the paddles
Pre-loop actions
Creating the while loop
Moving the paddles – keyboard events
Exiting the game – escape key
Paddle control – player 1
Paddle control – player 2
The increase and decrease value (-= and +=)
Testing section 2
Section 3 – moving the ball
Moving the ball – updating the location
Collision detection
Collision of the ball with the top and the bottom of the screen
Collision of the paddle with the top and the bottom of screen
Collision of the ball with the paddles
Testing – section 3
Section 4 – draw screen and track the score
The render screen – show what's happened
Displaying player scores
Ending the program
Play Tiny Tennis!
Summary
10. Keep Coding!
What we learned and your next steps
Classes and objects – very important next steps!
More fun with games
Adding music to games
Adding graphics to games
Remake or design games
Other games
PB-Ball
Snake
Other uses of Python
SciPy
iPython
MatPlotLib
Raspberry Pi
Coding challenges
Summary
A. Quick Task Answers
Chapter 1, Welcome! Let's Get Started
Chapter 2, Variables, Functions, and Users
Chapter 3, Calculate This!
Chapter 4, Making Decisions – Python Control Flows
Chapter 5, Loops and Logic
Chapter 6, Working with Data – Lists and Dictionaries
Chapter 7, What's in Your Backpack?
Chapter 8, pygame
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜