python for kids

348 1.3K 1
python  for  kids

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

PYTHON FOR KIDS PYTHON FOR KIDS A Playful Introduction to Programming Jason R. Briggs Python is a powerful, expressive program- ming language that’s easy to learn and fun to use! But books about learning to program in Python can be kind of dull, gray, and boring, and that’s no fun for anyone. Python for Kids brings Python to life and brings you (and your parents) into the world of programming. The ever-patient Jason R. Briggs will guide you through the basics as you experi- ment with unique (and often hilarious) example programs that feature ravenous monsters, secret agents, thieving ravens, and more. New terms are defined; code is colored, dissected, and explained; and quirky, full-color illustrations keep things on the lighter side. Chapters end with programming puzzles designed to stretch your brain and strengthen your understanding. By the end of the book you’ll have programmed two complete games: a clone of the famous Pong and “Mr. Stick Man Races for the Exit”—a platform game with jumps, animation, and much more. As you strike out on your programming adventure, you’ll learn how to: M Use fundamental data structures like lists, tuples, and maps M Organize and reuse your code with func- tions and modules M Use control structures like loops and conditional statements M Draw shapes and patterns with Python’s turtle module M Create games, animations, and other graphical wonders with tkinter Why should serious adults have all the fun? Python for Kids is your ticket into the amaz- ing world of computer programming. ABOUT THE AUTHOR Jason R. Briggs has been a programmer since the age of eight, when he first learned BASIC on a Radio Shack TRS-80. He has written software professionally as a developer and systems archi- tect and served as Contributing Editor for Java Developer’s Journal. His articles have appeared in JavaWorld, ONJava, and ONLamp. Python for Kids is his first book. SHELVE IN: PROGRAMMING LANGUAGES/PYTHON www.nost arch.com THE FINEST IN GEEK ENTERTAINMENT ™ For kids aged 10+ (and their parents) real programming. real easy. REAL Programming. REAL EASY. $34.95 ($36.95 CDN) Illustrations by Miran Lipovaca PYTHON FOR KIDS Briggs PYTHON FOR KIDS www.it-ebooks.info www.it-ebooks.info Python for Kids www.it-ebooks.info www.it-ebooks.info Python forKids A Playful Introduction to Programming By Jason R. Briggs San Francisco www.it-ebooks.info PYTHON FOR KIDS. Copyright © 2013 by Jason R. Briggs. All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. First printing 16 15 14 13 12 1 2 3 4 5 6 7 8 9 ISBN-10: 1-59327-407-6 ISBN-13: 978-1-59327-407-8 Publisher: William Pollock Production Editor: Serena Yang Cover and Interior Design: Octopod Studios Illustrator: Miran Lipovaca Developmental Editor: William Pollock Technical Reviewers: Josh Pollock and Maria Fernandez Copyeditor: Marilyn Smith Compositor: Serena Yang Proofreader: Greg Teague For information on book distributors or translations, please contact No Starch Press, Inc. directly: No Starch Press, Inc. 38 Ringold Street, San Francisco, CA 94103 phone: 415.863.9900; fax: 415.863.9950; info@nostarch.com; http://www.nostarch.com/ Library of Congress Cataloging-in-Publication Data A catalog record of this book is available from the Library of Congress. No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it. www.it-ebooks.info BRIEF CONTENTS About the Author, Illustrator, and Technical Reviewers xv Acknowledgments xvii Introduction xix Part I: Learning to Program Chapter 1: Not All Snakes Slither 3 Chapter 2: Calculations and Variables 15 Chapter 3: Strings, Lists, Tuples, and Maps 25 Chapter 4: Drawing with Turtles 43 Chapter 5: Asking Questions with if and else 53 Chapter 6: Going Loopy 67 Chapter 7: Recycling Your Code with Functions and Modules 81 Chapter 8: How to Use Classes and Objects 93 Chapter 9: Python’s Built-in Functions 109 Chapter 10: Useful Python Modules 129 Chapter 11: More Turtle Graphics 145 Chapter 12: Using tkinter for Better Graphics 163 Part II: Bounce! Chapter 13: Beginning Your First Game: Bounce! 193 Chapter 14: Finishing Your First Game: Bounce! 205 Part III : Mr. Stick Man Races for the Exit Chapter 15: Creating Graphics for the Mr. Stick Man Game 221 Chapter 16: Developing the Mr. Stick Man Game 233 Chapter 17: Creating Mr. Stick Man 251 Chapter 18: Completing the Mr. Stick Man Game 259 Afterword: Where to Go from Here 285 Appendix: Python Keywords 293 Glossary 307 Index 313 www.it-ebooks.info www.it-ebooks.info CONTENTS IN DETAIL About the Author, Illustrator, and Technical Reviewers xv Acknowledgments xvii Introduction xix Why Python? xx How to Learn to Code xx Who Should Read This Book xxi What’s in This Book xxii The Companion Website xxiii Have Fun! xxiii Part I: Learning to Program 1 Not All Snakes Slither 3 A Few Words About Language 4 Installing Python 5 Installing Python on Windows 7 5 Installing Python on Mac OS X 7 Installing Python on Ubuntu 9 Once You’ve Installed Python 10 Saving Your Python Programs 12 What You Learned 13 2 Calculations and Variables 15 Calculating with Python 16 Python Operators 17 The Order of Operations 18 Variables Are Like Labels 19 Using Variables 21 What You Learned 23 www.it-ebooks.info viii Contents in Detail 3 Strings, Lists, Tuples,and Maps 25 Strings 26 Creating Strings 26 Handling Problems with Strings 27 Embedding Values in Strings 30 Multiplying Strings 31 Lists Are More Powerful Than Strings 32 Adding Items to a List 35 Removing Items from a List 35 List Arithmetic 36 Tuples 38 Python Maps Won’t Help You Find Your Way 39 What You Learned 41 Programming Puzzles 41 #1: Favorites 41 #2: Counting Combatants 42 #3: Greetings! 42 4 Drawing with Turtles 43 Using Python’s turtle Module 44 Creating a Canvas 44 Moving the Turtle 46 What You Learned 51 Programming Puzzles 51 #1: A Rectangle 51 #2: A Triangle 51 #3: A Box Without Corners 51 5 Asking Questions withif and else 53 if Statements 54 A Block Is a Group of Programming Statements 54 Conditions Help Us Compare Things 57 if-then-else Statements 58 if and elif Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Combining Conditions 61 Variables with No Value—None 61 The Difference Between Strings and Numbers 62 What You Learned 65 www.it-ebooks.info [...]... use the programs developed by others, Python for Kids is a great place to start In the following chapters, you’ll find information to help you install Python, start the Python shell and perform basic calculations, print text on the screen and create lists, and perform simple control flow operations using if statements and for loops (and learn what if statements and for loops are!) You’ll learn how to... Python Installing Python is fairly straightforward Here, we’ll go over the steps for installing it on Windows 7, Mac OS X, and Ubuntu When installing Python, you’ll also set up a shortcut for the IDLE program, which is the Integrated DeveLopment Environment that lets you write programs for Python If Python has already been installed on your computer, jump ahead to “Once You’ve Installed Python on page... computer, jump ahead to “Once You’ve Installed Python on page 10 Installing Python on Windows 7 To install Python for Microsoft Windows 7, point a web browser to http://www .python. org/ and download the latest Windows installer for Python 3 Look for a section in the menu titled Quick Links, as shown here: NOTE The exact version of Python that you download is not important, as long as it starts with the... about the Python programming language make it extremely useful for beginners Most importantly, you can use Python to write simple, efficient programs really quickly Python doesn’t have a lot of complicated symbols, like braces ({ }), hashes (#), and dollar signs ($), which make other programming languages a lot more difficult to read and, therefore, a lot less friendly to beginners Installing Python Installing... only blame a personal character flaw for any probable goofs Particular thanks to Josh for some great suggestions and some really good catches And apologies to Maria for having to deal with occasionally dodgily formatted code Thanks to my wife and daughter, for putting up with a husband and father who had his nose buried in a computer screen even more than usual To Mum, for endless amounts of encouragement... programming languages named after people (like Ada and Pascal), those named using simple acronyms (like BASIC and FORTRAN), and even a few named after TV shows, like Python Yes, the Python programming language was named after the Monty Python s Flying Circus TV show, not after python the snake NOTE Monty Python s Flying Circus was an alternative British comedy show first broadcast in the 1970s, and it remains... instructions to install Python in the default location, as follows: 1 Select Install for All Users, and then click Next 2 Leave the default directory unchanged, but note the name of the installation directory (probably C: \Python3 1 or C:\ Python3 2) Click Next 3 Ignore the Customize Python section of the installation, and click Next At the end of this process, you should have a Python 3 entry in your... can skip to “Once You’ve Installed Python on page 10 to get started with Python Installing Python on Mac OS X If you’re using a Mac, you should find a version of Python pre­ installed, but it’s probably an older version of the language To be sure that you’re running the newest version, point your browser to http://www .python. org/getit/ to download the latest installer for the Mac There are two different... double-click Python. mpkg, and then follow the instructions to install the software You’ll be prompted for the administrator password for your Mac before Python installs (Don’t have the administrator password? Your parent may need to enter it.) Next, you need to add a script to the desktop for launching Python s IDLE application, as follows: 1 Click the Spotlight icon, the small magnifying glass at the... to -n): open -a "/Applications /Python 3.2/IDLE.app" args -n You may need to change the directory depending on the version of Python you installed 8 Select File4Save, and enter IDLE as the name 9 Select Desktop from the Where dialog, and then click Save Now you can skip to “Once You’ve Installed Python on page 10 to get started with Python Installing Python on Ubuntu Python comes preinstalled on the . KIDS www.it-ebooks.info www.it-ebooks.info Python for Kids www.it-ebooks.info www.it-ebooks.info Python for Kids A Playful Introduction to Programming By Jason R. Briggs San Francisco www.it-ebooks.info PYTHON FOR KIDS. Copyright. ENTERTAINMENT ™ For kids aged 10+ (and their parents) real programming. real easy. REAL Programming. REAL EASY. $34.95 ($36.95 CDN) Illustrations by Miran Lipovaca PYTHON FOR KIDS Briggs PYTHON FOR KIDS www.it-ebooks.info www.it-ebooks.info Python. PYTHON FOR KIDS PYTHON FOR KIDS A Playful Introduction to Programming Jason R. Briggs Python is a powerful, expressive program- ming language

Ngày đăng: 05/05/2014, 16:44

Từ khóa liên quan

Mục lục

  • About the Author, Illustrator, and Technical Reviewers

  • Acknowledgments

  • Introduction

    • Why Python?

    • How to Learn to Code

    • Who Should Read This Book

    • What’s in This Book

    • The Companion Website

    • Have Fun!

    • Part I: Learning to Program

      • 1: Not All Snakes Slither

        • A Few Words About Language

        • Installing Python

          • Installing Python on Windows 7

          • Installing Python on Mac OS X

          • Installing Python on Ubuntu

          • Once You’ve Installed Python

          • Saving Your Python Programs

          • What You Learned

          • 2: Calculations and Variables

            • Calculating with Python

              • Python Operators

              • The Order of Operations

              • Variables Are Like Labels

              • Using Variables

              • What You Learned

Tài liệu cùng người dùng

Tài liệu liên quan