PDF Snake Wrangling for Kids - Learning to Program with Python

[Pages:160] Snake Wrangling for Kids, Learning to Program with Python by Jason R. Briggs

Version 0.7.7

Copyright c 2007.

Published by... ah, no one actually.

Cover art and illustrations by Nuthapitol C.

Website:

Thanks To: Guido van Rossum (for benevelont dictatorship of the Python language), the members of the Edu-Sig mailing list (for helpful advice and commentary), author David Brin (the original instigator of this book), Michel Weinachter (for providing better quality versions of the illustrations), and various people for providing feedback and errata, including: Paulo J. S. Silva, Tom Pohl, Janet Lathan, Martin Schimmels, and Mike Cariaso (among others). Anyone left off this list, who shouldn't have been, is entirely due to premature senility on the part of the author.

License:

This work is licensed under the Creative Commons Attribution-NoncommercialShare Alike 3.0 New Zealand License. To view a copy of this license, visit or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

Below is a summary of the license.

You are free:

? to Share to copy, distribute and transmit the work ? to Remix to adapt the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).

Noncommercial. You may not use this work for commercial purposes. Share Alike. If you alter, transform, or build upon this work, you may distribute

the resulting work only under the same or similar license to this one.

For any reuse or distribution, you must make clear to others the license terms of this work.

Any of the above conditions can be waived if you get permission from the copyright holder.

Nothing in this license impairs or restricts the author's moral rights.

Contents

Preface

v

1 Not all snakes will squish you

1

1.1 A Few Words About Language . . . . . . . . . . . . . . . . . . . . . 2

1.2 The Order of Non-venomousConstricting Serpentes. . . . . . . . . . . . 3

1.3 Your first Python program . . . . . . . . . . . . . . . . . . . . . . . . 4

1.4 Your Second Python program. . .the same again? . . . . . . . . . . . . 6

2 8 multiplied by 3.57 equals. . .

9

2.1 Use of brackets and "Order of Operations" . . . . . . . . . . . . . . . 11

2.2 There's nothing so fickle as a variable . . . . . . . . . . . . . . . . . . 13

2.3 Using Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2.4 A Piece of String? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

2.5 Tricks with Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.6 Not quite a shopping list . . . . . . . . . . . . . . . . . . . . . . . . . 19

2.7 Tuples and Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

2.8 Things to try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3 Turtles, and other slow moving creatures

25

3.1 Things to try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

4 How to ask a question

33

4.1 Do this. . . or ELSE!!! . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

i

4.2 Do this. . . or do this. . . or do this. . . or ELSE!!! . . . . . . . . . . . . 35 4.3 Combining conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.4 Emptiness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.5 What's the difference. . .? . . . . . . . . . . . . . . . . . . . . . . . . . 38

5 Again and again

41

5.1 When is a block not square? . . . . . . . . . . . . . . . . . . . . . . . 44

5.2 While we're talking about looping. . . . . . . . . . . . . . . . . . . . . 50

5.3 Things to try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

6 Sort of like recycling. . .

53

6.1 Bits and Pieces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

6.2 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

6.3 Things to try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

7 A short chapter about Files

63

8 Turtles galore

65

8.1 Colouring in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

8.2 Darkness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

8.3 Filling things . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

8.4 Things to try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

9 A bit graphic

81

9.1 Quick Draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83

9.2 Simple Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

9.3 Drawing Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

9.4 Drawing Arcs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

9.5 Drawing Ovals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

9.6 Drawing Polygons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

9.7 Drawing Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

9.8 Basic Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

ii

9.9 Reacting to events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

10 Where to go from here

103

A Python Keywords

105

B Built-in Functions

119

C A Few Python Modules

129

D Answers to "Things to try"

139

iii

iv

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download