├── .directory ├── .gitignore ├── en ├── Desktop │ └── test.txt ├── appendixa.tex ├── appendixb.tex ├── appendixc.tex ├── appendixd.tex ├── by-nc-sa.eps ├── ch1.tex ├── ch10.tex ├── ch2.tex ├── ch3.tex ├── ch4.tex ├── ch5.tex ├── ch6.tex ├── ch7.tex ├── ch8.tex ├── ch9.tex ├── check.py ├── cover-linux.png ├── cover-mac.png ├── cover-tn.png ├── cover-windows.png ├── cover.eps ├── cover.png ├── editions.svg ├── electrocute.eps ├── figure1.eps ├── figure10.eps ├── figure11.eps ├── figure12.eps ├── figure13.eps ├── figure14.eps ├── figure15.eps ├── figure16.eps ├── figure17.eps ├── figure18.eps ├── figure19.eps ├── figure2.eps ├── figure20.eps ├── figure21.eps ├── figure22.eps ├── figure23.eps ├── figure24.eps ├── figure25.eps ├── figure26.eps ├── figure27.eps ├── figure28.eps ├── figure29.eps ├── figure3.eps ├── figure30.eps ├── figure31.eps ├── figure32.eps ├── figure33.eps ├── figure34.eps ├── figure35.eps ├── figure36.eps ├── figure37.eps ├── figure38.eps ├── figure39.eps ├── figure4.eps ├── figure40.eps ├── figure41.eps ├── figure42.eps ├── figure43.eps ├── figure44.eps ├── figure45.eps ├── figure46.eps ├── figure47.eps ├── figure48.eps ├── figure49.eps ├── figure5.eps ├── figure6.eps ├── figure7.eps ├── figure8.eps ├── figure9.eps ├── frontmatter.tex ├── girlbubble.eps ├── illustrations.svg ├── islanders.eps ├── license.txt ├── linux-edition.eps ├── list.eps ├── longdiv.sty ├── mac-edition.eps ├── placeholder.eps ├── preface.tex ├── pullinghair.eps ├── python-powered-h.eps ├── python-powered.eps ├── setup.py ├── swfk.tex.pre ├── test.gif ├── test.txt ├── textedit-icon.eps ├── textedit-icon2.eps ├── trash.eps ├── turtle1.eps ├── turtle2.eps ├── versions.sty └── windows-edition.eps ├── readme.txt └── ru ├── .gitignore ├── 03.house.eps ├── 03.house.png ├── 03.house.py ├── 06.py ├── 07.py ├── 08.py ├── book-linux.pdf ├── book-macos.pdf ├── book-windows.pdf ├── book.tex ├── build.sh ├── chapter1.tex ├── chapter10.tex ├── chapter2.tex ├── chapter3.tex ├── chapter4.tex ├── chapter5.tex ├── chapter6.tex ├── chapter7.tex ├── chapter8.tex ├── chapter9.tex ├── figure36.png ├── frontmatter.tex ├── preface.tex ├── version-linux.tex ├── version-macos.tex ├── version-windows.tex └── version.tex /.directory: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Icon=folder-documents-text 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.synctex* 3 | *.idx 4 | *.log 5 | *.out 6 | *.toc 7 | *.aux 8 | *.ind 9 | *.ilg 10 | -------------------------------------------------------------------------------- /en/Desktop/test.txt: -------------------------------------------------------------------------------- 1 | this is a test 2 | -------------------------------------------------------------------------------- /en/appendixb.tex: -------------------------------------------------------------------------------- 1 | % appendixb.tex 2 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 3 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 4 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 5 | 6 | 7 | \chapter{Built-in Functions}\label{app:builtinfunctions} 8 | 9 | Python has a number of built-in functions---functions that can be used without needing to \textbf{import} them first. Some of the available built-in functions are listed below. 10 | 11 | \subsection*{abs}\index{functions!abs} 12 | 13 | The \textbf{abs} function returns the absolute value of a number. An absolute value is a number that is not negative. So the absolute value of 10 is 10, and the absolute value of -20.5 is 20.5. For example: 14 | 15 | \begin{listing} 16 | \begin{verbatim} 17 | >>> print(abs(10)) 18 | 10 19 | >>> print(abs(-20.5)) 20 | 20.5 21 | \end{verbatim} 22 | \end{listing} 23 | 24 | \subsection*{bool}\index{functions!bool} 25 | 26 | The \textbf{bool} function returns either True or False based on the value passed as its parameter. For numbers, 0 returns False, while any other number returns True: 27 | 28 | \begin{listing} 29 | \begin{verbatim} 30 | >>> print(bool(0)) 31 | False 32 | >>> print(bool(1)) 33 | True 34 | >>> print(bool(1123.23)) 35 | True 36 | >>> print(bool(-500)) 37 | True 38 | \end{verbatim} 39 | \end{listing} 40 | 41 | For other values, None returns False while anything else returns True: 42 | 43 | \begin{listing} 44 | \begin{verbatim} 45 | >>> print(bool(None)) 46 | False 47 | >>> print(bool('a')) 48 | True 49 | \end{verbatim} 50 | \end{listing} 51 | 52 | \subsection*{cmp}\index{functions!cmp} 53 | 54 | The \textbf{cmp} function compares two values and returns a negative number if the first value is less than the second; returns 0 if the first value is equal to the second; and returns a positive number if the first value is greater than the second. For example, 1 is less than 2: 55 | 56 | \begin{listing} 57 | \begin{verbatim} 58 | >>> print(cmp(1,2)) 59 | -1 60 | \end{verbatim} 61 | \end{listing} 62 | 63 | \noindent 64 | And 2 is equal to 2: 65 | 66 | \begin{listing} 67 | \begin{verbatim} 68 | >>> print(cmp(2,2)) 69 | 0 70 | \end{verbatim} 71 | \end{listing} 72 | 73 | \noindent 74 | But 2 is greater than 1: 75 | 76 | \begin{listing} 77 | \begin{verbatim} 78 | >>> print(cmp(2,1)) 79 | 1 80 | \end{verbatim} 81 | \end{listing} 82 | 83 | \noindent 84 | Compare doesn't only work with numbers. You can use other values, such as strings: 85 | 86 | \begin{listing} 87 | \begin{verbatim} 88 | >>> print(cmp('a','b')) 89 | -1 90 | >>> print(cmp('a','a')) 91 | 0 92 | >>> print(cmp('b','a')) 93 | 1 94 | \end{verbatim} 95 | \end{listing} 96 | 97 | \noindent 98 | But do be careful with strings; the return value may not be exactly what you expect$\ldots$ 99 | 100 | \begin{listing} 101 | \begin{verbatim} 102 | >>> print(cmp('a','A')) 103 | 1 104 | >>> print(cmp('A','a')) 105 | -1 106 | \end{verbatim} 107 | \end{listing} 108 | 109 | A lower-case 'a' is actually greater than an upper-case 'A'. Of course$\ldots$ 110 | 111 | \begin{listing} 112 | \begin{verbatim} 113 | >>> print(cmp('aaa','aaaa')) 114 | -1 115 | >>> print(cmp('aaaa','aaa')) 116 | 1 117 | \end{verbatim} 118 | \end{listing} 119 | 120 | \noindent 121 | $\ldots$3 letter a's (aaa) are less than 4 letter a's (aaaa). 122 | 123 | \subsection*{dir}\index{functions!dir} 124 | 125 | The \textbf{dir} function returns a list of information about a value. You can use dir on strings, numbers, functions, modules, objects, classes---pretty much anything. On some values, the information might not be all that useful (in fact it might not make a huge amount of sense at all). For example, calling dir on the number 1 results in$\ldots$ 126 | 127 | \begin{listingignore} 128 | \begin{verbatim} 129 | >>> dir(1) 130 | ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', 131 | '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__getattribute__', 132 | '__getnewargs__', '__hash__', '__hex__', '__index__', '__init__', '__int__', '__invert__', 133 | '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', 134 | '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', 135 | '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', 136 | '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', 137 | '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', 138 | '__xor__'] 139 | \end{verbatim} 140 | \end{listingignore} 141 | 142 | $\ldots$quite a large number of special functions. Whereas calling dir on the string 'a' results in... 143 | 144 | \begin{listingignore} 145 | \begin{verbatim} 146 | >>> dir('a') 147 | ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', 148 | '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', 149 | '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', 150 | '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', 151 | '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 152 | 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 153 | 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 154 | 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 155 | 'swapcase', 'title', 'translate', 'upper', 'zfill'] 156 | \end{verbatim} 157 | \end{listingignore} 158 | 159 | Which shows you there are functions such as \code{capitalize} (change the first letter in a string to a capital)$\ldots$ 160 | 161 | \begin{listing} 162 | \begin{verbatim} 163 | >>> print('aaaaa'.capitalize()) 164 | Aaaaa 165 | \end{verbatim} 166 | \end{listing} 167 | 168 | $\ldots$\code{isalnum} (which returns True if a string is alphanumeric---contains only letters and numbers), \code{isalpha} (which returns True if a string contains only letters), and so on. Dir can be useful when you have a variable and quickly want to find out what you can do with it. 169 | 170 | \subsection*{eval}\index{functions!eval} 171 | 172 | The \textbf{eval} function takes a string as a parameter and runs it as though it were a Python expression. This is similar to the \textbf{exec} keyword, but works a little differently. With exec you can create mini Python programs in your string, but eval only allows simple expressions, such as: 173 | 174 | \begin{listing} 175 | \begin{verbatim} 176 | >>> eval('10*5') 177 | 50 178 | \end{verbatim} 179 | \end{listing} 180 | 181 | \subsection*{file}\index{functions!file} 182 | 183 | A function to open a file and return a file object with functions that can access information in the file (the contents of the file, its size and so on). You can find more information about file and file objects in Chapter~\ref{ch:ashortchapteraboutfiles}. 184 | 185 | \subsection*{float}\index{functions!float} 186 | 187 | The \textbf{float} function converts a string or a number into a floating point number. A floating point number is a number with a decimal place (also called a real number). For example, the number 10 is an `integer' (also called a whole number), but 10.0, 10.1, 10.253, and so on, are all `floats'. You can convert a string to a float by calling: 188 | 189 | \begin{listing} 190 | \begin{verbatim} 191 | >>> float('12') 192 | 12.0 193 | \end{verbatim} 194 | \end{listing} 195 | 196 | \noindent 197 | You can use a decimal place in the string as well: 198 | 199 | \begin{listing} 200 | \begin{verbatim} 201 | >>> float('123.456789') 202 | 123.456789 203 | \end{verbatim} 204 | \end{listing} 205 | 206 | \noindent 207 | A number can be converted to a float by calling: 208 | 209 | \begin{listing} 210 | \begin{verbatim} 211 | >>> float(200) 212 | 200.0 213 | \end{verbatim} 214 | \end{listing} 215 | 216 | \noindent 217 | Of course, converting a floating point number just returns another floating point number: 218 | 219 | \begin{listing} 220 | \begin{verbatim} 221 | >>> float(100.123) 222 | 100.123 223 | \end{verbatim} 224 | \end{listing} 225 | 226 | \noindent 227 | Calling float with no arguments, returns 0.0. 228 | 229 | \subsection*{int}\index{functions!int} 230 | 231 | The \textbf{int} function converts a string or a number into a whole number (or integer). For example: 232 | 233 | \begin{listing} 234 | \begin{verbatim} 235 | >>> int(123.456) 236 | 123 237 | >>> int('123') 238 | 123 239 | \end{verbatim} 240 | \end{listing} 241 | 242 | This function works a little differently from the \textbf{float} function. If you try to convert a floating point number in a string, you will get an error message: 243 | 244 | \begin{listing} 245 | \begin{verbatim} 246 | >>> int('123.456') 247 | Traceback (most recent call last): 248 | File "", line 1, in 249 | ValueError: invalid literal for int() with base 10: '123.456' 250 | \end{verbatim} 251 | \end{listing} 252 | 253 | \noindent 254 | However, if you call int with no argument, then 0 is returned. 255 | 256 | \subsection*{len}\index{functions!len} 257 | 258 | The \textbf{len} function returns the length of an object. In this case of a string, it returns the number of characters in the string: 259 | 260 | \begin{listing} 261 | \begin{verbatim} 262 | >>> len('this is a test string') 263 | 21 264 | \end{verbatim} 265 | \end{listing} 266 | 267 | \noindent 268 | For a list or a tuple, it returns the number of items: 269 | 270 | \begin{listing} 271 | \begin{verbatim} 272 | >>> mylist = [ 'a', 'b', 'c', 'd' ] 273 | >>> print(len(mylist)) 274 | 4 275 | >>> mytuple = (1,2,3,4,5,6) 276 | >>> print(len(mytuple)) 277 | 6 278 | \end{verbatim} 279 | \end{listing} 280 | 281 | \noindent 282 | For a map, it also returns the number of items: 283 | 284 | \begin{listing} 285 | \begin{verbatim} 286 | >>> mymap = { 'a' : 100, 'b' : 200, 'c' : 300 } 287 | >>> print(len(mymap)) 288 | 3 289 | \end{verbatim} 290 | \end{listing} 291 | 292 | \noindent 293 | You might find the len function useful with loops, if you want to count through the elements in a list. You could do this using the following code: 294 | 295 | \begin{listing} 296 | \begin{verbatim} 297 | >>> mylist = [ 'a', 'b', 'c', 'd' ] 298 | >>> for item in mylist: 299 | ... print(item) 300 | \end{verbatim} 301 | \end{listing} 302 | 303 | \noindent 304 | Which would print out all the items in the list (a,b,c,d)---but what if you wanted to print the index position of each item in the list? In this case we could find the length of the list, then count through the items as follows: 305 | 306 | \begin{listing} 307 | \begin{verbatim} 308 | >>> mylist = [ 'a', 'b', 'c', 'd' ] 309 | >>> length = len(mylist) 310 | >>> for x in range(0, length): 311 | ... print('the item at index %s is %s' % (x, mylist[x])) 312 | ... 313 | the item at index 0 is a 314 | the item at index 1 is b 315 | the item at index 2 is c 316 | the item at index 3 is d 317 | \end{verbatim} 318 | \end{listing} 319 | 320 | \noindent 321 | We store the length of the list in the variable `length', and then use that variable in the \code{range} function to create our loop. 322 | 323 | \subsection*{max}\index{functions!max} 324 | 325 | The \textbf{max} function returns the largest item in a list, tuple or even a string. For example: 326 | 327 | \begin{listing} 328 | \begin{verbatim} 329 | >>> mylist = [ 5, 4, 10, 30, 22 ] 330 | >>> print(max(mylist)) 331 | 30 332 | \end{verbatim} 333 | \end{listing} 334 | 335 | \noindent 336 | A string with the items are separated by commas or spaces will also work: 337 | 338 | \begin{listing} 339 | \begin{verbatim} 340 | >>> s = 'a,b,d,h,g' 341 | >>> print(max(s)) 342 | h 343 | \end{verbatim} 344 | \end{listing} 345 | 346 | \noindent 347 | And you don't have to use lists, or tuples or strings. You can also call the max function directly with a number of arguments: 348 | 349 | \begin{listing} 350 | \begin{verbatim} 351 | >>> print(max(10, 300, 450, 50, 90)) 352 | 450 353 | \end{verbatim} 354 | \end{listing} 355 | 356 | \subsection*{min}\index{functions!min} 357 | 358 | The \textbf{min} function works in the same way as max, except it returns the smallest item in the list/tuple/string: 359 | 360 | \begin{listing} 361 | \begin{verbatim} 362 | >>> mylist = [ 5, 4, 10, 30, 22 ] 363 | >>> print(min(mylist)) 364 | 4 365 | \end{verbatim} 366 | \end{listing} 367 | 368 | \subsection*{range}\index{functions!range} 369 | 370 | The \textbf{range} function is mainly used in for-loops, when you want to loop through some code a number of times. We first saw range in Chapter~\ref{ch:againandagain}, so we've seen how to use it with two arguments, but it can also be used with three arguments. Here's another example of range with two arguments: 371 | 372 | \begin{listing} 373 | \begin{verbatim} 374 | >>> for x in range(0, 5): 375 | ... print(x) 376 | ... 377 | 0 378 | 1 379 | 2 380 | 3 381 | 4 382 | \end{verbatim} 383 | \end{listing} 384 | 385 | \noindent 386 | What you might not have realised, is that the \code{range} function actually just returns a special object (called an iterator) which the for-loop then works through. You can convert the iterator into a list (oddly enough, using the function \code{list}), so if you print the return value when calling range, you'll see the numbers it contains: 387 | 388 | \begin{listing} 389 | \begin{verbatim} 390 | >>> print(list(range(0, 5))) 391 | [0, 1, 2, 3, 4] 392 | \end{verbatim} 393 | \end{listing} 394 | 395 | \noindent 396 | You get a list of numbers that can be assigned to variables and used elsewhere in your program: 397 | 398 | \begin{listingignore} 399 | \begin{verbatim} 400 | >>> my_list_of_numbers = list(range(0, 30)) 401 | >>> print(my_list_of_numbers) 402 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 403 | 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] 404 | \end{verbatim} 405 | \end{listingignore} 406 | 407 | \noindent 408 | Range also takes a third argument, called a `step' (the first two arguments are called the `start' and the `stop'). If the step value is not passed into the function (in other words, when you call it with only the start and stop values), by default the number 1 is used. But what happens when we pass the number 2 as the step? You can see the result in the following example: 409 | 410 | \begin{listing} 411 | \begin{verbatim} 412 | >>> my_list_of_numbers = list(range(0, 30, 2)) 413 | >>> print(my_list_of_numbers) 414 | [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28] 415 | \end{verbatim} 416 | \end{listing} 417 | 418 | \noindent 419 | Each number in the list increases by 2 from the previous number. We can use larger steps: 420 | 421 | \begin{listing} 422 | \begin{verbatim} 423 | >>> mylist = list(range(0, 500, 50)) 424 | >>> print(mylist) 425 | [0, 50, 100, 150, 200, 250, 300, 350, 400, 450] 426 | \end{verbatim} 427 | \end{listing} 428 | 429 | This creates a list from 0 to 500 (but not including 500, of course), incrementing the numbers by 50. 430 | 431 | \subsection*{sum}\index{functions!sum} 432 | 433 | The \textbf{sum} function adds up items in a list and returns the total number. For example: 434 | 435 | \begin{listing} 436 | \begin{verbatim} 437 | >>> mylist = list(range(0, 500, 50)) 438 | >>> print(mylist) 439 | [0, 50, 100, 150, 200, 250, 300, 350, 400, 450] 440 | 441 | >>> print(sum(mylist)) 442 | 2250 443 | \end{verbatim} 444 | \end{listing} 445 | 446 | \newpage -------------------------------------------------------------------------------- /en/ch1.tex: -------------------------------------------------------------------------------- 1 | % ch1.tex 2 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 3 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 4 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 5 | 6 | 7 | \chapter{Not all snakes will squish you}\label{ch:notallsnakeswillsquishyou} 8 | 9 | Chances are you were given this book for your birthday. Or possibly for Christmas. Aunty Mildred was going to give you mismatching socks that were two sizes too large (and you wouldn't want to wear when you grew into them anyway). Instead, she heard someone talking about this printable book, remembered you had one of those computer-thingamabobs that you tried to show her how to use last Christmas (you gave up when she started trying to talk into the mouse), and got them to print another copy. Just be thankful you didn't get the mouldy old socks. 10 | 11 | I hope you're not too disappointed that I popped out of the recycled wrapping paper, instead. A not-quite-so-talkative (okay, not-talking-at-all) book, with an ominous looking title on the front about ``Learning$\ldots$''. 12 | But take a moment to think about how I feel. If you were the character from that novel about wizards that is sitting on the bookshelf in your bedroom, I'd possibly have teeth... or perhaps even eyes. I might have moving pictures inside me, or be able to make moaning ghostly sounds when you opened my pages. Instead, I'm printed out on dog-eared A4 sheets of paper, stapled together or perhaps bound in a folder. How would I know---I don't have eyes. 13 | \\ 14 | \\ 15 | \emph{I'd give anything for a nice, sharp set of teeth$\ldots$} 16 | \\ 17 | \\ 18 | However it's not as bad as it sounds. Even if I can't talk... or bite your fingers when you're not looking... I can tell you a little bit about what makes computers work. Not the physical stuff, with wires and computer-chips and cables and devices that would, more than likely, electrocute you as soon as you touched them (so don't!!)---but the hidden stuff running around inside those wires and computer-chips and cables and bits, which make computers actually useful. 19 | 20 | \begin{wrapfigure}{r}{0.5\textwidth} 21 | \begin{center} 22 | \includegraphics*[width=70mm]{electrocute.eps} 23 | \end{center} 24 | \end{wrapfigure} 25 | 26 | It's a little like thoughts running around inside your head. If you didn't have thoughts you'd be sitting on the floor of your bedroom, staring vacantly at the door and drooling down the front of your t-shirt. Without \emph{programs}, computers would only be useful as a doorstop---and even then they wouldn't be very useful, because you'd keep tripping over them in the night. And there's nothing worse than a stubbed toe in the dark. 27 | \\ 28 | \\ 29 | \emph{I'm just a book and even I know that.} 30 | \\ 31 | \\ 32 | Your family may have a Playstation, Xbox or Wii sitting in the lounge---they're not much use without programs (Games) to make them work. Your DVD player, possibly your fridge and even your car, all have computer programs to make them more helpful than they would be otherwise. Your DVD player has programs to help it figure out what to play on a DVD; your fridge might have a simple program to make sure it doesn't use too much electricity, but still keep your food cold; your car might have a computer with a program to warn the driver if they're about to bump into something.\\ 33 | If you know how to write computer programs, you can do all sorts of useful things. Perhaps write your own games. Create web pages that actually do stuff, instead of just sitting there looking somewhat colourful. Being able to program could possibly even help with your homework.\\ 34 | \\ 35 | That said, let's get onto something a bit more interesting. 36 | 37 | \section{A Few Words About Language} 38 | 39 | Just like humans, certainly whales, possibly dolphins, and maybe even parents (although that's debatable), computers have their own language. Actually, also like humans, they have more than one language. There are languages covering just about all the letters of the alphabet. A, B, C, D and E are not only letters, they're also programming languages (which proves that adults have no imagination, and should be made to read either a dictionary or a thesaurus before naming anything). 40 | 41 | There are programming languages named after people, named using simple acronyms (the capital letters of a series of words), and just a few named after a TV show. Oh, and if you add a few pluses and hashes (+, \#) after a couple of those letters I just listed---that's yet another couple of programming languages as well. Making matters worse, some of the languages are almost the same, and differ only slightly. 42 | \\ 43 | \\ 44 | \emph{What did I tell you? No imagination!} 45 | \\ 46 | \\ 47 | Luckily, many of these languages have fallen into disuse, or vanished completely; but the list of different ways you can `talk' to a computer is still rather worryingly large. I'm only going to discuss one of them---otherwise we might as well not even get started. 48 | \\ 49 | It would be more productive to sit in your bedroom and drool down the front of your t-shirt$\ldots$ 50 | 51 | \section{The Order of Non-venomous\\Constricting Serpentes$\ldots$} 52 | 53 | $\ldots$or Pythons, for short. 54 | 55 | Apart from being a snake, Python\index{Python} is also a programming language. However, it was not named after a legless reptile; rather it is one of the few programming languages named after a TV show. Monty Python was a British comedy show popular during the 1970's (and still popular now, actually), which you have to be a certain age to find amusing. Anyone below the age of about$\ldots$ let's say 12$\ldots$ will wonder what all the fuss is all about\footnote{Except the fish slapping dance. That's funny no matter how old you are.}. 56 | 57 | There are a number of things about Python (the programming language, not the snake, nor the TV show) that make it extremely useful when you're learning to program. For us, at the moment, the most important reason is that you can start it up and do stuff really quickly. 58 | 59 | This is the part where you hope Mum, Dad (or whomever is in charge of the computer), has read the part at the beginning of this book labelled ``A Note for Mums and Dads''. 60 | 61 | \noindent 62 | There's a good way to find out if they actually have read it: 63 | 64 | \begin{WINDOWS} 65 | Click on the Start button at the bottom left of the screen, click on `All Programs' (which has a green triangle next to it), and hopefully in the list of programs you should see `Python 2.5' (or something like it). Figure~\ref{fig1} shows you what you should be looking for. Click on `Python (command line)' and you should see something like Figure~\ref{fig2}. 66 | 67 | \begin{figure} 68 | \begin{center} 69 | \includegraphics[width=80mm]{figure1.eps} 70 | \end{center} 71 | \caption{Python in the Windows menu.}\label{fig1} 72 | \end{figure} 73 | 74 | \begin{figure} 75 | \begin{center} 76 | \includegraphics[width=135mm]{figure2.eps} 77 | \end{center} 78 | \caption{The Python console on Windows.}\label{fig2} 79 | \end{figure} 80 | \end{WINDOWS} 81 | 82 | \begin{MAC} 83 | In Finder, on the left you should see a group called `Applications'. Click on this, and then find a program called `Terminal' (it'll probably be in a folder called `Utilities'). 84 | Click on `Terminal', and when it starts up, type python and hit enter. You'll should hopefully be looking at a window that looks like Figure~\ref{fig3}. 85 | 86 | \begin{figure} 87 | \begin{center} 88 | \includegraphics[width=85mm]{figure3.eps} 89 | \end{center} 90 | \caption{The Python console on Mac OSX.}\label{fig3} 91 | \end{figure} 92 | \end{MAC} 93 | 94 | \begin{LINUX} 95 | Ask Mum or Dad which terminal application you should use (it could be one called `Konsole', `rxvt', `xterm' or any one of a dozen different programs---which is why you'll probably need to ask). Start the terminal program and type `python' (without the quotes), and hit enter. You should see something like Figure~\ref{fig4}. 96 | 97 | \begin{figure} 98 | \begin{center} 99 | \includegraphics[width=80mm]{figure4.eps} 100 | \end{center} 101 | \caption{The Python console on Linux.}\label{fig4} 102 | \end{figure} 103 | \end{LINUX} 104 | 105 | \subsection*{\color{BrickRed}If you discover they haven't read the section in the beginning$\ldots$} 106 | 107 | $\ldots$because there is something missing when you try to follow those instructions---then turn to the front of the book, poke it under their nose while they're trying to read the newspaper, and look hopeful. Saying, ``please please please please'' over and over again, until it becomes annoying, might work quite well, if you're having trouble convincing them to get off the couch. Of course, the other thing you can do, is turn to the front of the book, and follow the instructions in the Preface to install Python yourself. 108 | 109 | \section{Your first Python program} 110 | 111 | With any luck, if you've reached this point, you've managed to start up the Python console, which is one way of running Python commands and programs. When you first start the console (or after entering a command), you'll see what's called a `prompt'. In the Python console\index{Python console}, the prompt is three chevrons, or greater-than symbols ($>$) pointing to the right: 112 | 113 | \begin{listing} 114 | \begin{verbatim} 115 | >>> 116 | \end{verbatim} 117 | \end{listing} 118 | 119 | If you put enough Python commands together, you have a program that you can run in more than just the console$\ldots$ but for the moment we're going to keep things simple, and type our commands directly in the console, at the prompt ($>>>$). So, why not start with typing the following: 120 | 121 | \begin{listing} 122 | \begin{verbatim} 123 | print("Hello World") 124 | \end{verbatim} 125 | \end{listing} 126 | 127 | Make sure you include the quotes (that's these: $"$ $"$), and hit enter at the end of the line. Hopefully you'll see something like the following: 128 | 129 | \begin{listing} 130 | \begin{verbatim} 131 | >>> print("Hello World") 132 | Hello World 133 | \end{verbatim} 134 | \end{listing} 135 | 136 | The prompt reappears, to let you know that the Python console is ready to accept more commands. 137 | 138 | \noindent 139 | Congratulations! You've just created your first Python program. \code{print} is a function that writes whatever is inside the brackets out to the console--we'll use it more later. 140 | 141 | \section{Your Second Python program$\ldots$the same again?} 142 | 143 | Python programs wouldn't be all that useful if you had to type the commands every single time you wanted to do something---or if you wrote a program for someone, and they had to type it in before they could use it. 144 | 145 | The Word Processor that you might be using to write your school assignments, is probably somewhere between 10 and 100 million lines of code. Depending upon how many lines you printed on one page (and whether or not you printed on both sides of the paper), this could be around 400,000 printed pages$\ldots$ or a stack of paper about 40 metres high. 146 | Just imagine when you brought that software home from the shop, there would be quite a few trips back and forth to the car, to carry that much paper$\ldots$ 147 | 148 | $\ldots$and you'd better hope there's no big gust of wind while you're carrying those stacks. Luckily, there's an alternative to all this typing---or no one would get anything done. 149 | 150 | \begin{center} 151 | \includegraphics*[width=85mm]{pullinghair.eps} 152 | \end{center} 153 | 154 | \begin{WINDOWS} 155 | Open Notepad (Click on Start, All Programs, and it should be in the Accessories sub menu), and then type the print command exactly as you typed it into the console before: 156 | 157 | \begin{listing} 158 | \begin{verbatim} 159 | print("Hello World") 160 | \end{verbatim} 161 | \end{listing} 162 | 163 | Click on the File menu (in Notepad), then Save, and when prompted for a file name, call it \emph{hello.py} and save it on your Desktop. Double-click on the icon for hello.py on your Desktop (see Figure~\ref{fig5}) and for a brief moment a console window will appear. It will vanish too quickly for you too make out the words, but Hello World will have been printed to the screen for a fraction of a second---we'll come back to this later and prove that it did.\\ 164 | 165 | \begin{figure} 166 | \begin{center} 167 | \includegraphics[width=58mm]{figure5.eps} 168 | \end{center} 169 | \caption{hello.py icon on the Windows Desktop.}\label{fig5} 170 | \end{figure} 171 | \end{WINDOWS} 172 | 173 | \begin{MAC} 174 | Open up the Text Editor by clicking on its icon. It may be in the Dock at the bottom of the screen \includegraphics*[width=12mm]{textedit-icon.eps}, or look for this icon \includegraphics*[width=19mm]{textedit-icon2.eps} in the Applications list in Finder. Type the print command exactly as you typed it into the console earlier: 175 | 176 | \begin{listing} 177 | \begin{verbatim} 178 | print("Hello World") 179 | \end{verbatim} 180 | \end{listing} 181 | 182 | Click on the File menu, then click on Save, and when you are prompted for a file name, call it hello.py and save it into your home directory (your home directory is on the left under Places--ask Mum or Dad to point it out for you). 183 | 184 | Open the `Terminal' application again--it will automatically start up in your home directory--and type the following: 185 | 186 | \begin{listing} 187 | \begin{verbatim} 188 | python hello.py 189 | \end{verbatim} 190 | \end{listing} 191 | 192 | You should see Hello World written to the window exactly as it was when you typed the command in the Python console. 193 | 194 | \end{MAC} 195 | 196 | \begin{LINUX} 197 | Open a text editor (again you might have to ask Mum or Dad which one to use), then type the print command exactly as you typed it into the console: 198 | 199 | \begin{listing} 200 | \begin{verbatim} 201 | print("Hello World") 202 | \end{verbatim} 203 | \end{listing} 204 | 205 | Click on the File menu, then Save, and when prompted for a file name, call it hello.py and save it in your Home folder (there might be an icon called `Home' somewhere in the Save dialog box). Next open up the terminal application (again Konsole, rxvt, etc... what we used earlier), and type: 206 | 207 | \begin{listing} 208 | \begin{verbatim} 209 | python hello.py 210 | \end{verbatim} 211 | \end{listing} 212 | 213 | You should see Hello World written to the window exactly as it was when you typed the command in the Python console (see Figure~\ref{fig9}). 214 | 215 | \begin{figure} 216 | \begin{center} 217 | \includegraphics[width=75mm]{figure9.eps} 218 | \end{center} 219 | \caption{Running a python program from a text file on Linux.}\label{fig9} 220 | \end{figure} 221 | \end{LINUX} 222 | 223 | So you can now see that the nice people who created Python, have kindly saved you from having to type the same thing over and over and over and over and over again. Like they did back in the 1980's. No, I'm serious---they did. Go and ask your Dad if he ever owned a ZX81 when he was younger?\\ 224 | 225 | \noindent 226 | If he did you can point at him and laugh.\\ 227 | 228 | \noindent 229 | Trust me on this one. You won't get it. But he will.\footnote{The Sinclair ZX81, released in the 1980's was one of the first affordable home computers. A number of young boys and girls were driven completely mad, typing in the code for games printed in popular ZX81 magazines---only to discover, after hours of typing, that the darn things never worked properly.} 230 | 231 | \noindent 232 | \emph{Be prepared to run away though.} 233 | 234 | \subsection*{\color{BrickRed}The End of the Beginning} 235 | 236 | Welcome to the wonderful world of Programming. We've started really simply with a ``Hello World'' application---everyone starts with that, when they're learning to program. 237 | In the next chapter we'll start to do some more useful things with the Python console and then look at what goes into making a program. 238 | 239 | \newpage -------------------------------------------------------------------------------- /en/ch10.tex: -------------------------------------------------------------------------------- 1 | % ch10.tex 2 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 3 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 4 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 5 | 6 | 7 | \chapter{Where to go from here} 8 | 9 | Congratulations! You've made it to the end. 10 | \par 11 | What you've hopefully learned from this book, are basic concepts that will make learning other programming languages much simpler. While Python is a brilliant programming language, one language is not \emph{always} the best tool for every task. So don't be afraid of looking at other ways to program your computer, if it interests you. 12 | 13 | For example, if you're interested in games programming, you can perhaps look at something like BlitzBasic (\href{http://www.blitzbasic.com}{www.blitzbasic.com}), which uses the Basic programming language. Or perhaps Flash (which is used by many websites for animation and games---for example, the Nickelodeon website, \href{http://www.nick.com}{www.nick.com}, uses a lot of Flash). 14 | 15 | If you're interested in programming Flash games, possibly a good place to start would be `Beginning Flash Games Programming for Dummies', a book written by Andy Harris, or a more advanced reference such as `The Flash 8 Game Developing Handbook' by Serge Melnikov. Searching for `flash games' on \href{http://www.amazon.com}{www.amazon.com} will find a number of books on this subject. 16 | 17 | Some other games programming books are: `Beginner's Guide to DarkBASIC Game Programming' by Jonathon S Harbour (also using the Basic programming language), and `Game Programming for Teens' by Maneesh Sethi (using BlitzBasic). Be aware that BlitzBasic, DarkBasic and Flash (at least the development tools) all cost money (unlike Python), so Mum or Dad will have to get involved before you can even get started. 18 | 19 | If you want to stick to Python for games programming, a couple of places to look are: \href{http://www.pygame.org}{www.pygame.org}, and the book `Game Programming With Python' by Sean Riley. 20 | 21 | If you're not specifically interested in games programming, but do want to learn more about Python (more advanced programming topics), then take a look at `Dive into Python' by Mark Pilgrim (\href{http://www.diveintopython.org}{www.diveintopython.org}). There's also a free tutorial for Python available at: \href{http://docs.python.org/tut/tut.html}{http://docs.python.org/tut/tut.html}. There's a whole pile of topics we haven't covered in this basic introduction so, at least from the Python perspective, there's still a lot for you to learn and play with. 22 | \par\par\noindent 23 | \emph{Good luck and enjoy your programming efforts.} 24 | 25 | \newpage -------------------------------------------------------------------------------- /en/ch3.tex: -------------------------------------------------------------------------------- 1 | % ch3.tex 2 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 3 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 4 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 5 | 6 | 7 | \chapter{Turtles, and other slow moving creatures}\index{turtle}\label{ch:turtles} 8 | 9 | There are certain similarities between turtles in the real world and a Python turtle. In the real world, a turtle is a (sometimes) green reptile that moves around very slowly and carries its house on its back. In the world of Python, a turtle is a small black arrow that moves very slowly around the screen. No mention of house-carrying though. 10 | 11 | In fact, considering that a Python turtle leaves a trail as it moves around the screen, this makes it less like a real turtle, and more like a snail or a slug. However, I suppose that a module called `slug' wouldn't be particularly attractive, so it makes sense to stick with turtles. Just imagine the turtle is carrying a couple of marker pens with it, and drawing as it goes. 12 | 13 | In the deep, dark, and distant past, there was a simple programming language called Logo. Logo was used to control a robot turtle (called Irving). Over time, the turtle evolved from a robot that could move around the floor, to a small arrow moving around a screen. 14 | 15 | \emph{Which just goes to show, things don't always improve as technology advances---a little robot turtle would be a lot more fun.} 16 | 17 | Python's turtle module (we'll come to modules a bit later, but for now just just think of a module as something we can use inside a program) is a little bit like the Logo programming language, but while Logo was (is) fairly limited, Python has many more capabilities. The turtle module itself, is a useful way to learn how computers draw pictures on your computer screen. 18 | 19 | Let's get started and see just how it works. The first step is to tell Python we want to use turtle, by importing the module: 20 | 21 | \begin{listing} 22 | \begin{verbatim} 23 | >>> import turtle 24 | \end{verbatim} 25 | \end{listing} 26 | 27 | Then we need to display a canvas to draw on. A canvas is just like the material an artist might use for painting; in this case it's a blank space for drawing on: 28 | 29 | \begin{listing} 30 | \begin{verbatim} 31 | >>> t = turtle.Pen() 32 | \end{verbatim} 33 | \end{listing} 34 | 35 | In this code, we call a special function (Pen\index{Pen}) on the module turtle, which automatically creates a canvas we can draw on. A function is a re-useable piece of code (again we'll come to functions later) that does something useful---in this case, an object which represents the turtle is returned by the Pen function---we set that object to the variable `t' (in effect we're giving our turtle canvas the name `t'). When you type the code into the Python console, you'll see a blank box (the canvas) appear, looking something like figure~\ref{fig10}. 36 | 37 | \begin{figure} 38 | \begin{center} 39 | \includegraphics[width=72mm]{figure10.eps} 40 | \end{center} 41 | \caption{An arrow representing the turtle.}\label{fig10} 42 | \end{figure} 43 | 44 | \emph{Yes, that little arrow in the middle of the screen really is the turtle. And, no, it's not very turtle-like.} 45 | 46 | You can send instructions to the turtle, by using functions on the object that was created (by calling \code{turtle.Pen})---since we assigned that object to the variable \code{t}, we use \code{t} to send the instructions. 47 | One turtle instruction is \code{forward}. Forward\index{turtle!forward} tells the turtle to move forward in whatever direction she is facing (I have no idea whether it's a boy or a girl turtle, but let's just assume it's a girl-turtle for the moment). Let's tell the turtle to move forward 50 pixels (we'll talk about pixels in a minute): 48 | 49 | \begin{listing} 50 | \begin{verbatim} 51 | >>> t.forward(50) 52 | \end{verbatim} 53 | \end{listing} 54 | 55 | You should see something like figure~\ref{fig11}. 56 | 57 | \begin{figure} 58 | \begin{center} 59 | \includegraphics[width=72mm]{figure11.eps} 60 | \end{center} 61 | \caption{The turtle draws a line.}\label{fig11} 62 | \end{figure} 63 | 64 | From the turtle's point-of-view, she has moved forward 50 steps. From our point-of-view, she has moved 50 pixels. 65 | 66 | \noindent 67 | \emph{So, what's a pixel?} 68 | 69 | A pixel\index{pixels} is a dot on the screen. When you look at your computer, everything is made up of tiny (square) dots. The programs you use and the games you play on the computer, or with a Playstation, or an Xbox, or a Wii; are all made up of a whole bunch of different coloured dots, arranged on the screen. In fact, if you look at your computer screen with a magnifying glass, you might just be able to make out some of those dots. So if we zoom in on the canvas and the line that was just drawn by the turtle, we can see the arrow representing the turtle, is also just a bunch of square dots, as you can see in figure~\ref{fig12}. 70 | 71 | \begin{figure} 72 | \begin{center} 73 | \includegraphics[width=72mm]{figure12.eps} 74 | \end{center} 75 | \caption{Zooming in on the line and the arrow.}\label{fig12} 76 | \end{figure} 77 | 78 | We'll talk more about these dots, or pixels, in a later chapter. 79 | 80 | Next, we can tell the turtle to turn left\index{turtle!turning left} or right\index{turtle!turning right}: 81 | 82 | \begin{listing} 83 | \begin{verbatim} 84 | >>> t.left(90) 85 | \end{verbatim} 86 | \end{listing} 87 | 88 | This tells the turtle to turn left, 90 degrees. You may not have learned about degrees\index{degrees} in school so far, but the easiest way to think about them, is that they are like the divisions on the face of a clock as seen in figure~\ref{fig13}. 89 | 90 | \begin{figure} 91 | \begin{center} 92 | \includegraphics[width=52mm]{figure13.eps} 93 | \end{center} 94 | \caption{The `divisions' on a clock.}\label{fig13} 95 | \end{figure} 96 | 97 | The difference to a clock, is that rather than 12 divisions (or 60, if you're counting minutes rather than hours), there are 360 divisions. So, if you count 360 divisions around the face of a clock, you get 90 where there's normally a 3, 180 where there's normally a 6, and 270 where there's normally a 9; and 0 would be at the top (at the start), where you normally see a 12. Figure~\ref{fig14} shows you the degree divisions. 98 | 99 | \begin{figure} 100 | \begin{center} 101 | \includegraphics[width=52mm]{figure14.eps} 102 | \end{center} 103 | \caption{Degrees.}\label{fig14} 104 | \end{figure} 105 | 106 | So, what does it actually mean when you call \code{left(90)}? 107 | \par 108 | If you stand and face one direction, point your arm out directly away from your shoulder, THAT is 90 degrees. If you point your left arm, that's 90 degrees left. If you point your right arm, that's 90 degrees right. When Python's turtle turns left, she plants her nose in one spot then swivels her body around the face the new direction (same as if you turned your body to face where your arm is pointing). So, \code{t.left(90)} results in the arrow now pointing upwards, as shown in figure~\ref{fig15}. 109 | 110 | \begin{figure} 111 | \begin{center} 112 | \includegraphics[width=72mm]{figure15.eps} 113 | \end{center} 114 | \caption{The turtle after turning left.}\label{fig15} 115 | \end{figure} 116 | 117 | Let's try the same commands again a few times: 118 | 119 | \begin{listing} 120 | \begin{verbatim} 121 | >>> t.forward(50) 122 | >>> t.left(90) 123 | >>> t.forward(50) 124 | >>> t.left(90) 125 | >>> t.forward(50) 126 | >>> t.left(90) 127 | \end{verbatim} 128 | \end{listing} 129 | 130 | Our turtle has drawn a square and is left facing the same direction as she started (see figure~\ref{fig16}). 131 | 132 | \begin{figure} 133 | \begin{center} 134 | \includegraphics[width=72mm]{figure16.eps} 135 | \end{center} 136 | \caption{Drawing a square.}\label{fig16} 137 | \end{figure} 138 | 139 | We can erase what's on the canvas by using clear\index{turtle!clear}: 140 | 141 | \begin{listing} 142 | \begin{verbatim} 143 | >>> t.clear() 144 | \end{verbatim} 145 | \end{listing} 146 | 147 | Some of the other basic functions you can use with your turtle are: \code{reset}\index{turtle!reset}, which also clears the screen, but puts the turtle automatically back into her starting position; \code{backward}\index{turtle!backward}, which moves the turtle backwards; \code{right}, which turns the turtle to the right; \code{up}\index{turtle!up (stop drawing)} which tells the turtle to stop drawing as she moves (in other words pick her pen up off the canvas); and finally \code{down}\index{turtle!down (start drawing)} which tells the turtle to start drawing again. You call these functions in the same way we've used the others: 148 | 149 | \begin{listing} 150 | \begin{verbatim} 151 | >>> t.reset() 152 | >>> t.backward(100) 153 | >>> t.right(90) 154 | >>> t.up() 155 | >>> t.down() 156 | \end{verbatim} 157 | \end{listing} 158 | 159 | \noindent 160 | We'll come back to the turtle module shortly. 161 | 162 | \section{Things to try} 163 | 164 | \emph{In this chapter we saw how to use turtle to draw simple lines, using left and right turns. We saw that turtle uses degrees to turn, a bit like the minute divisions on a clock face.} 165 | 166 | \subsection*{Exercise 1} 167 | Create a canvas using turtle's \code{Pen} function, and draw a rectangle. 168 | 169 | \subsection*{Exercise 2} 170 | Create another canvas using turtles \code{Pen} function, and draw a triangle. 171 | 172 | \newpage -------------------------------------------------------------------------------- /en/ch4.tex: -------------------------------------------------------------------------------- 1 | % ch4.tex 2 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 3 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 4 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 5 | 6 | 7 | \chapter{How to ask a question}\label{ch:howtoaskaquestion} 8 | 9 | In programming terms, a question usually means we want to do either one thing, or another, depending upon the answer to the question. This is called an \textbf{if-statement}\index{if-statement}. For example: 10 | 11 | \begin{quotation} 12 | How old are you? If you're older than 20, you're too old! 13 | \end{quotation} 14 | 15 | This might be written in Python as the following if-statement: 16 | 17 | \begin{listing} 18 | \begin{verbatim} 19 | if age > 20: 20 | print('you are too old!') 21 | \end{verbatim} 22 | \end{listing} 23 | 24 | An if-statement is made up of an `if' followed by what is called a `condition' (more on that in a second), followed by a colon (:). The lines following the if must be in a block---and if the answer to the question is `yes' (or True, as we call it in programming terms) the commands in the block will be run. 25 | \par 26 | A condition\index{conditions} is a programming statement that returns `yes' (True) or `no' (False). There are certain symbols (or operators) used to create conditions, such as: 27 | 28 | \begin{center} 29 | \begin{tabular}{|c|c|} 30 | \hline 31 | == & equals \\ 32 | \hline 33 | != & not equals \\ 34 | \hline 35 | $>$ & greater than \\ 36 | \hline 37 | $<$ & less than \\ 38 | \hline 39 | $>$= & greater than or equal to \\ 40 | \hline 41 | $<$= & less than or equal to \\ 42 | \hline 43 | \end{tabular} 44 | \end{center} 45 | 46 | For example, if you are 10 years old, then the condition \code{your\_age == 10} would return True (yes), but if you are not 10, it would return False. Remember: don't mix up the \textbf{two} equals symbols used in a condition (==), with the equals used in assigning values (=)---if you use a single = symbol in a \emph{condition}, you'll get an error message. 47 | \par 48 | Assuming you set the variable \code{age} to your age, then if you are 12 years old, the condition$\ldots$ 49 | 50 | \begin{listing} 51 | \begin{verbatim} 52 | age > 10 53 | \end{verbatim} 54 | \end{listing} 55 | 56 | $\ldots$ would again return True. If you are 8 years old, it would return False. If you are 10 years old, it would also return False---because the condition is checking for greater than ($>$) 10, and not greater than or equal ($>$=) to 10. 57 | 58 | Let's try a few examples: 59 | 60 | \begin{listing} 61 | \begin{verbatim} 62 | >>> age = 10 63 | >>> if age > 10: 64 | ... print('got here') 65 | \end{verbatim} 66 | \end{listing} 67 | 68 | \noindent 69 | If you enter the above example into the console, what might happen? 70 | \par 71 | \noindent 72 | Nothing. 73 | \par 74 | \noindent 75 | Because the value of the variable \code{age} is not greater than 10, the print command in the block will not be run. How about: 76 | 77 | \begin{listingignore} 78 | \begin{verbatim} 79 | >>> age = 10 80 | >>> if age >= 10: 81 | ... print('got here') 82 | \end{verbatim} 83 | \end{listingignore} 84 | 85 | If you try this example, then you should see the message got here printed to the console. The same will happen for the next example: 86 | 87 | \begin{listing} 88 | \begin{verbatim} 89 | >>> age = 10 90 | >>> if age == 10: 91 | ... print('got here') 92 | got here 93 | \end{verbatim} 94 | \end{listing} 95 | 96 | \section{Do this$\ldots$ or ELSE!!!} 97 | 98 | We can also extend an if-statement, so that it does something when a condition is not true. For example, print the word `Hello' out to the console if your age is 12, but print `Goodbye' if it's not. To do this, we use an if-then-else-statement\index{if-then-else-statement} (this is another way of saying \emph{``if something is true, then do \textbf{this}, otherwise do \textbf{that}''}): 99 | 100 | \begin{listing} 101 | \begin{verbatim} 102 | >>> age = 12 103 | >>> if age == 12: 104 | ... print('Hello') 105 | ... else: 106 | ... print('Goodbye') 107 | Hello 108 | \end{verbatim} 109 | \end{listing} 110 | 111 | Type in the above example and you should see `Hello' printed to the console. Change the value of the variable \code{age} to another number, and `Goodbye' will be printed: 112 | 113 | \begin{listing} 114 | \begin{verbatim} 115 | >>> age = 8 116 | >>> if age == 12: 117 | ... print('Hello') 118 | ... else: 119 | ... print('Goodbye') 120 | 121 | Goodbye 122 | \end{verbatim} 123 | \end{listing} 124 | 125 | \section{Do this$\ldots$ or do this$\ldots$ or do this$\ldots$ or ELSE!!!} 126 | 127 | We can extend an if-statement even further using elif (short for else-if). For example, we can check if your age is 10, or if it's 11, or if it's 12 and so on: 128 | 129 | \begin{listing} 130 | \begin{verbatim} 131 | 1. >>> age = 12 132 | 2. >>> if age == 10: 133 | 3. ... print('you are 10') 134 | 4. ... elif age == 11: 135 | 5. ... print('you are 11') 136 | 6. ... elif age == 12: 137 | 7. ... print('you are 12') 138 | 8. ... elif age == 13: 139 | 9. ... print('you are 13') 140 | 10. ... else: 141 | 11. ... print('huh?') 142 | 12. ... 143 | 13. you are 12 144 | \end{verbatim} 145 | \end{listing} 146 | 147 | In the code above, line 2 checks whether the value of the age variable is equal to 10. It's not, so it then jumps to line 4 to check whether the value of the \code{age} variable is equal to 11. Again, it's not, so it jumps to line 6 to check whether the variable is equal to 12. In this case it is, so Python moves to the block in line 7, and runs the print command. (Hopefully you've also noticed that there are 5 groups in this code---lines 3, 5, 7, 9 and line 11) 148 | 149 | \section{Combining conditions}\index{conditions!combining} 150 | You can combine conditions together using the keywords `and' and `or'. We can shrink the example above, a little, by using `or' to join the conditions together: 151 | 152 | \begin{listing} 153 | \begin{verbatim} 154 | 1. >>> if age == 10 or age == 11 or age == 12 or age == 13: 155 | 2. ... print('you are %s' % age) 156 | 3. ... else: 157 | 4. ... print('huh?') 158 | \end{verbatim} 159 | \end{listing} 160 | 161 | If any of the conditions in line 1 are true (i.e. if age is 10 \textbf{or} age is 11 \textbf{or} age is 12 \textbf{or} age is 13), then the block of code in line 2 is run, otherwise Python moves to line 4. We could shrink the example a little bit more by using the `and', $>$= and $<$= symbols: 162 | 163 | \begin{listing} 164 | \begin{verbatim} 165 | 1. >>> if age >= 10 and age <= 13: 166 | 2. ... print('you are %s' % age) 167 | 3. ... else: 168 | 4. ... print('huh?') 169 | \end{verbatim} 170 | \end{listing} 171 | 172 | Hopefully, you've figured out that if \textbf{both} the conditions on line 1 are true then the block of code in line 2 is run (if age is greater than or equal to 10 \textbf{and} age is less than or equal to 13). So if the value of the variable age is 12, then `you are 12' would be printed to the console: because 12 is greater than 10 and it is also less than 13. 173 | 174 | \section{Emptiness}\index{None} 175 | 176 | There is another sort of value, that can be assigned to a variable, that we didn't talk about in the previous chapter: \textbf{Nothing}. 177 | \par 178 | In the same way that numbers, strings and lists are all values that can be assigned to a variable, `nothing' is also a kind of value that can be assigned. In Python, an empty value is referred to as \code{None} (in other programming languages, it is sometimes called null) and you can use it in the same way as other values: 179 | 180 | \begin{listing} 181 | \begin{verbatim} 182 | >>> myval = None 183 | >>> print(myval) 184 | None 185 | \end{verbatim} 186 | \end{listing} 187 | 188 | None is a way to reset a variable back to being un-used, or can be a way to create a variable without setting its value before it is used. 189 | \par 190 | For example, if your football team were raising funds for new uniforms, and you were adding up how much money had been raised, you might want to wait until all the team had returned with the money before you started adding it all up. In programming terms, we might have a variable for each member of the team, and then set all the variables to None: 191 | 192 | \begin{listing} 193 | \begin{verbatim} 194 | >>> player1 = None 195 | >>> player2 = None 196 | >>> player3 = None 197 | \end{verbatim} 198 | \end{listing} 199 | 200 | We could then use an if-statement, to check these variables, to determine if all the members of the team had returned with the money they'd raised: 201 | 202 | \begin{listing} 203 | \begin{verbatim} 204 | >>> if player1 is None or player2 is None or player3 is None: 205 | ... print('Please wait until all players have returned') 206 | ... else: 207 | ... print('You have raised %s' % (player1 + player2 + player3)) 208 | \end{verbatim} 209 | \end{listing} 210 | 211 | The if-statement checks whether any of the variables have a value of \code{None}, and prints the first message if they do. If each variable has a real value, then the second message is printed with the total money raised. If you try this code out with all variables set to None, you'll see the first message (don't forget to create the variables first or you'll get an error message): 212 | 213 | \begin{listing} 214 | \begin{verbatim} 215 | >>> if player1 is None or player2 is None or player3 is None: 216 | ... print('Please wait until all players have returned') 217 | ... else: 218 | ... print('You have raised %s' % (player1 + player2 + player3)) 219 | Please wait until all players have returned 220 | \end{verbatim} 221 | \end{listing} 222 | 223 | Even if we set one or two of the variables, we'll still get the message: 224 | 225 | \begin{listing} 226 | \begin{verbatim} 227 | >>> player1 = 100 228 | >>> player3 = 300 229 | >>> if player1 is None or player2 is None or player3 is None: 230 | ... print('Please wait until all players have returned') 231 | ... else: 232 | ... print('You have raised %s' % (player1 + player2 + player3)) 233 | Please wait until all players have returned 234 | \end{verbatim} 235 | \end{listing} 236 | 237 | \noindent 238 | Finally, once all variables are set, you'll see the message in the second block: 239 | 240 | \begin{listing} 241 | \begin{verbatim} 242 | >>> player1 = 100 243 | >>> player3 = 300 244 | >>> player2 = 500 245 | >>> if player1 is None or player2 is None or player3 is None: 246 | ... print('Please wait until all players have returned') 247 | ... else: 248 | ... print('You have raised %s' % (player1 + player2 + player3)) 249 | You have raised 900 250 | \end{verbatim} 251 | \end{listing} 252 | 253 | \section{What's the difference$\ldots$?}\label{whatsthedifference}\index{equality} 254 | 255 | What's the difference between \code{10} and \code{'10'}? 256 | \par 257 | Not much apart from the quotes, you might be thinking. Well, from reading the earlier chapters, you know that the first is a number and the second is a string. This makes them differ more than you might expect. Earlier we compared the value of a variable (age) to a number in an if-statement: 258 | 259 | \begin{listing} 260 | \begin{verbatim} 261 | >>> if age == 10: 262 | ... print('you are 10') 263 | \end{verbatim} 264 | \end{listing} 265 | 266 | If you set variable age to 10, the print statement will be called: 267 | 268 | \begin{listing} 269 | \begin{verbatim} 270 | >>> age = 10 271 | >>> if age == 10: 272 | ... print('you are 10') 273 | ... 274 | you are 10 275 | \end{verbatim} 276 | \end{listing} 277 | 278 | However, if age is set to \code{'10'} (note the quotes), then it won't: 279 | 280 | \begin{listing} 281 | \begin{verbatim} 282 | >>> age = '10' 283 | >>> if age == 10: 284 | ... print('you are 10') 285 | ... 286 | \end{verbatim} 287 | \end{listing} 288 | 289 | Why is the code in the block not run? Because a string is different from a number, even if they look the same: 290 | 291 | \begin{listing} 292 | \begin{verbatim} 293 | >>> age1 = 10 294 | >>> age2 = '10' 295 | >>> print(age1) 296 | 10 297 | >>> print(age2) 298 | 10 299 | \end{verbatim} 300 | \end{listing} 301 | 302 | See! They look exactly the same. Yet, because one is a string, and the other is a number, they are different values. Therefore age == 10 (age equals 10) will never be true, if the value of the variable is a string. 303 | \par 304 | Probably the best way to think about it, is to consider 10 books and 10 bricks. The number of items might be the same, but you couldn't say that 10 books are exactly the same as 10 bricks, could you? Luckily in Python we have magic functions which can turn strings into numbers and numbers into strings (even if they won't quite turn bricks into books). For example, to convert the string '10' into a number you would use the function \code{int}: 305 | 306 | \begin{listing} 307 | \begin{verbatim} 308 | >>> age = '10' 309 | >>> converted_age = int(age) 310 | \end{verbatim} 311 | \end{listing} 312 | 313 | \noindent 314 | The variable converted\_age now holds the number 10, and not a string. To convert a number into a string, you would use the function \code{str}: 315 | 316 | \begin{listing} 317 | \begin{verbatim} 318 | >>> age = 10 319 | >>> converted_age = str(age) 320 | \end{verbatim} 321 | \end{listing} 322 | 323 | \noindent 324 | converted\_age now holds the string 10, and not a number. Back to that if-statement which prints nothing: 325 | 326 | \begin{listing} 327 | \begin{verbatim} 328 | >>> age = '10' 329 | >>> if age == 10: 330 | ... print('you are 10') 331 | ... 332 | \end{verbatim} 333 | \end{listing} 334 | 335 | \noindent 336 | If we convert the variable \emph{before} we check, then we'll get a different result: 337 | 338 | \begin{listing} 339 | \begin{verbatim} 340 | >>> age = '10' 341 | >>> converted_age = int(age) 342 | >>> if converted_age == 10: 343 | ... print('you are 10') 344 | ... 345 | you are 10 346 | \end{verbatim} 347 | \end{listing} 348 | 349 | \newpage -------------------------------------------------------------------------------- /en/ch7.tex: -------------------------------------------------------------------------------- 1 | % ch7.tex 2 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 3 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 4 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 5 | 6 | 7 | \chapter{A short chapter about Files}\label{ch:ashortchapteraboutfiles}\index{functions!file} 8 | 9 | You probably know what a file is already. 10 | \par 11 | \noindent 12 | If your parents have a home office, chances are they've got a file cabinet of some sort. Various important papers (mostly boring adult stuff) are stored in those cabinets, usually in cardboard folders labelled with letters of the alphabet, or months of the year. Files on a computer are rather similar to those cardboard folders. They have labels (the name of the file), and are used to store important information. The drawers on a file cabinet, which might be used to organise paperwork so they are easier to find, are similar to directories (or folders) on a computer. 13 | \par 14 | We've already created a file object, using Python, in the previous chapter. The example looked like this: 15 | 16 | \begin{WINDOWS} 17 | 18 | \begin{listing} 19 | \begin{verbatim} 20 | >>> f = open('c:\\test.txt') 21 | >>> print(f.read()) 22 | \end{verbatim} 23 | \end{listing} 24 | 25 | \end{WINDOWS} 26 | 27 | \begin{MAC} 28 | 29 | \begin{listing} 30 | \begin{verbatim} 31 | >>> f = open('Desktop/test.txt') 32 | >>> print(f.read()) 33 | \end{verbatim} 34 | \end{listing} 35 | 36 | \end{MAC} 37 | 38 | \begin{LINUX} 39 | 40 | \begin{listing} 41 | \begin{verbatim} 42 | >>> f = open('Desktop/test.txt') 43 | >>> print(f.read()) 44 | \end{verbatim} 45 | \end{listing} 46 | 47 | \end{LINUX} 48 | 49 | A file object doesn't just have the function \code{read}\index{functions!file!read}. After all, file cabinets wouldn't be very useful if you could only open a drawer and take papers out, but could never put them back in. We can create a new, empty file, by passing another parameter when we call the \code{file} function: 50 | 51 | \begin{listing} 52 | \begin{verbatim} 53 | >>> f = open('myfile.txt', 'w') 54 | \end{verbatim} 55 | \end{listing} 56 | 57 | 'w' is the way we tell Python we want to write to the file object, and not read from it. We can now add information to the file using the function \code{write}\index{functions!file!write}. 58 | 59 | \begin{listing} 60 | \begin{verbatim} 61 | >>> f = open('myfile.txt', 'w') 62 | >>> f.write('this is a test file') 63 | \end{verbatim} 64 | \end{listing} 65 | 66 | Then we need to tell Python when we're finished with the file, and don't want to write to it any more---we use the function \code{close}\index{functions!file!close} to do this. 67 | 68 | \begin{listing} 69 | \begin{verbatim} 70 | >>> f = open('myfile.txt', 'w') 71 | >>> f.write('this is a test file') 72 | >>> f.close() 73 | \end{verbatim} 74 | \end{listing} 75 | 76 | If you open the file using your favourite editor, you will see it contains the text: ``this is a test file''. Or better yet, we can use Python to read it in again: 77 | 78 | \begin{listing} 79 | \begin{verbatim} 80 | >>> f = open('myfile.txt') 81 | >>> print(f.read()) 82 | this is a test file 83 | \end{verbatim} 84 | \end{listing} 85 | 86 | \newpage -------------------------------------------------------------------------------- /en/check.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | 3 | import os 4 | import re 5 | import sys 6 | from io import StringIO 7 | 8 | pat = re.compile(r'\\begin{listing}\s*\\begin{verbatim}\s*(.*?)\\end{verbatim}', re.DOTALL | re.MULTILINE) 9 | split_re = re.compile(r'\s*') 10 | line_re = re.compile(r'^\s*[0-9]+\.\s*') 11 | 12 | stdout = sys.stdout 13 | 14 | def build_example(srclines, wantlines): 15 | for x in range(0, len(wantlines)): 16 | if wantlines[x].rstrip() == '(continues on...)': 17 | wantlines = wantlines[0:x] 18 | break 19 | 20 | return Example('\n'.join(srclines).lstrip().rstrip().replace('\r\n', '\n'), 21 | '\n'.join(wantlines).lstrip().rstrip().replace('\r\n', '\n')) 22 | 23 | def parse(source): 24 | examples = [] 25 | src = [] 26 | want = [] 27 | parsing_src = False 28 | parsing_want = False 29 | for line in source.split('\n'): 30 | line = line_re.sub('', line) 31 | if line.startswith('>>> ') or line.startswith('...'): 32 | if parsing_want: 33 | examples.append(build_example(src, want)) 34 | src = [] 35 | want = [] 36 | parsing_src = True 37 | src.append(line[4:]) 38 | elif not parsing_src and not parsing_want: 39 | continue 40 | else: 41 | want.append(line) 42 | parsing_want = True 43 | if len(src) > 0: 44 | examples.append(build_example(src, want)) 45 | return examples 46 | 47 | 48 | class Example(object): 49 | def __init__(self, source, want): 50 | self.source = source 51 | self.want = want 52 | 53 | def __str__(self): 54 | return 'src=\n%s\nwant=\n%s' % (self.source, self.want) 55 | 56 | def percent_match(tokenlist, str): 57 | count = 0 58 | for token in tokenlist: 59 | if str.find(token) >= 0: 60 | count += 1 61 | return (count / len(tokenlist)) 62 | 63 | 64 | def run(example): 65 | sio = StringIO() 66 | if len(example.source.split('\n')) > 1: 67 | kind = 'exec' 68 | else: 69 | kind = 'single' 70 | 71 | l = [] 72 | sys.stdout = sio 73 | try: 74 | code = compile(example.source, '', kind) 75 | exec(code, globals()) 76 | val = sio.getvalue().rstrip() 77 | if example.want != '' and val.find(example.want) < 0: 78 | return 'expected: "%s"\nactual: "%s"' % (example.want, val) 79 | except Exception as se: 80 | sys.stdout = stdout 81 | err = str(se) 82 | tokens = split_re.split(err[0:err.find('(')]) 83 | match = percent_match(tokens, example.want) 84 | if match < 0.7: 85 | return 'expected: %s\nactual: %s\n(%% match = %s)' % (example.want, str(se), match) 86 | finally: 87 | sys.stdout = stdout 88 | 89 | return None 90 | 91 | 92 | s = open(sys.argv[1]).read() 93 | 94 | sys.stdin = StringIO() 95 | 96 | success = 0 97 | failure = 0 98 | linenum = 1 99 | for mat in pat.finditer(s): 100 | code = mat.group(1) 101 | print('\n\ncode #%s' % linenum) 102 | linenum = linenum + 1 103 | examples = parse(code) 104 | for example in examples: 105 | response = run(example) 106 | if response: 107 | print('exec:\n%s' % example.source) 108 | print(response) 109 | failure = failure + 1 110 | else: 111 | success = success + 1 112 | 113 | print('%s tests succeeded' % success) 114 | print('%s tests failed' % failure) 115 | -------------------------------------------------------------------------------- /en/cover-linux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/en/cover-linux.png -------------------------------------------------------------------------------- /en/cover-mac.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/en/cover-mac.png -------------------------------------------------------------------------------- /en/cover-tn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/en/cover-tn.png -------------------------------------------------------------------------------- /en/cover-windows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/en/cover-windows.png -------------------------------------------------------------------------------- /en/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/en/cover.png -------------------------------------------------------------------------------- /en/editions.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 21 | 28 | 29 | 49 | 51 | 52 | 54 | image/svg+xml 55 | 57 | 58 | 59 | 60 | 64 | Linux Edition 75 | Mac Edition 86 | 94 | Windows Edition 105 | 113 | 121 | OLPC Edition 132 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /en/figure31.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: GIMP PostScript file plugin V 1.17 by Peter Kirchgessner 3 | %%Title: figure31.eps 4 | %%CreationDate: Mon Nov 19 00:11:43 2007 5 | %%DocumentData: Clean7Bit 6 | %%LanguageLevel: 2 7 | %%Pages: 1 8 | %%BoundingBox: 14 14 109 80 9 | %%EndComments 10 | %%BeginProlog 11 | % Use own dictionary to avoid conflicts 12 | 10 dict begin 13 | %%EndProlog 14 | %%Page: 1 1 15 | % Translate for offset 16 | 14.173228346456694 14.173228346456694 translate 17 | % Translate to begin of first scanline 18 | 0 64.997822080750538 translate 19 | 93.996850393700782 -64.997822080750538 scale 20 | % Image geometry 21 | 94 65 8 22 | % Transformation matrix 23 | [ 94 0 0 65 0 0 ] 24 | % Strings to hold RGB-samples per scanline 25 | /rstr 94 string def 26 | /gstr 94 string def 27 | /bstr 94 string def 28 | {currentfile /ASCII85Decode filter /RunLengthDecode filter rstr readstring pop} 29 | {currentfile /ASCII85Decode filter /RunLengthDecode filter gstr readstring pop} 30 | {currentfile /ASCII85Decode filter /RunLengthDecode filter bstr readstring pop} 31 | true 3 32 | %%BeginData: 6765 ASCII Bytes 33 | colorimage 34 | rrAr>rr@Q~> 35 | rrArerr@Q~> 36 | rrAs7rr@Q~> 37 | !<=7?AcX"SJ,~> 38 | !<>WfU]EscJ,~> 39 | !<@#8iW3osJ,~> 40 | !?c!P8-(OiJ,~> 41 | !Crr`Oo]SnJ,~> 42 | !H-nph#X`tJ,~> 43 | !?c!P6NK"dJ,~> 44 | !Crr`MZIigJ,~> 45 | !H-npe,cdkJ,~> 46 | !?c!h4odG/0E 47 | !Crs#KE-/aC&iDSKE6*`J,~> 48 | !H-o3b5es>U]@h#b5nhbJ,~> 49 | !?c!i3<:rjn65oI2#TE81a%;~> 50 | !Crs$IK=S+n< 51 | !H-o4_Z@0@nBD!0[JduDY\ns~> 52 | !?c!i3<1c$>6$AU3<:rZJ,~> 53 | !Crs$IK4-NPQ5IsIK=IZJ,~> 54 | !H-o4_uQY%c2a^>_u[)[J,~> 55 | !?c!i3<1c$>6$AU3<:rZJ,~> 56 | !Crs$IfO9PPlPUuIfXR[J,~> 57 | !H-o4`;le'cN'j@` 58 | !?c!i3WLo&>Q?MW3WV&[J,~> 59 | !Crs$J,jERQ2kb"J,s[\J,~> 60 | !H-o4`W2q)ciC!B`W<;]J,~> 61 | !?c"K3WW 62 | !Crs[JH;G$rdk+Ld=D:7m[!ojrIFui7t:~> 63 | !H-ok`rXrhrl>'=dDl6cma2$5rPnrCDL_~> 64 | !?c"K3rf3`002/os!lGX!&=CWs8W"&s8W"&!&=F5!AkpL~> 65 | !Crs[JcG`RA:]=3s'*p&!,_Y#s8W"`s8W"`!,_[c!HL\\~> 66 | !H-okaoDAEQc[ALs,POL!35tGs8W#Gs8W#G!36">!O-Hl~> 67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GUaRB0/Z1%^R"RjFeY\ns~> 193 | "s@MD47E4LZ1%^R"ReE<1a%;~> 194 | #"PJLJa`X=Z1%^R"Rgo%E^tW~> 195 | #&`GUaRB0/Z1%^R"RjFeY\ns~> 196 | "s@MD47E4LZ1%^R"ReE<1a%;~> 197 | #"PJLJa`X=Z1%^R"Rgo%E^tW~> 198 | #&`GUaRB0/Z1%^R"RjFeY\ns~> 199 | "s@MD47E4LZ1%^R"ReE<1a%;~> 200 | #"PJLJa`X=Z1%^R"Rgo%E^tW~> 201 | #&`GUaRB0/Z1%^R"RjFeY\ns~> 202 | "s@MD47E4LZ1%^R"ReE<1a%;~> 203 | #"PJLJa`X=Z1%^R"Rgo%E^tW~> 204 | #&`GUaRB0/Z1%^R"RjFeY\ns~> 205 | "s@MD47E4LZ1%^R"ReE<1a%;~> 206 | #"PJLJa`X=Z1%^R"Rgo%E^tW~> 207 | #&`GUaRB0/Z1%^R"RjFeY\ns~> 208 | "s@MD47E4LZ1%^R"ReE<1a%;~> 209 | #"PJLJa`X=Z1%^R"Rgo%E^tW~> 210 | #&`GUaRB0/Z1%^R"RjFeY\ns~> 211 | "s@MD47E4LYE&hT4$b\GJ,~> 212 | #"PJLJa`X=YE&hTJW=b@J,~> 213 | #&`GUaRB0/YE&hTaP=";J,~> 214 | "X%DC47E3PNs+o55r9^7~> 215 | "\5AKJa`WANs+p&NcIX?~> 216 | "`E>TaRB/3Ns+pmgot[H~> 217 | "!D2A40.fP4$b\GJ,~> 218 | "%T/IJZJ5AJW=b@J,~> 219 | ")d,RaK+b3aP=";J,~> 220 | "!D2A6*!*I5liebJ,~> 221 | "%T/INiRa2NWF/jJ,~> 222 | ")d,RgoJNrg]=WsJ,~> 223 | !?c!P5liebJ,~> 224 | !Crr`NWF/jJ,~> 225 | !H-npg]=WsJ,~> 226 | !?c!O1]SYK~> 227 | !Crr_EWAU[~> 228 | !H-noYQ/Qk~> 229 | !!&i 230 | !!&ic!!%N~> 231 | !!&j5!!%N~> 232 | %%EndData 233 | showpage 234 | %%Trailer 235 | end 236 | %%EOF 237 | -------------------------------------------------------------------------------- /en/frontmatter.tex: -------------------------------------------------------------------------------- 1 | \pagestyle{empty} 2 | \frontmatter 3 | \begin{FRONTCOVER} 4 | \begin{titlepage} 5 | \begin{textblock*}{210mm}(0mm,0mm) 6 | \includegraphics[width=0.9\paperwidth]{cover.eps} 7 | \end{textblock*} 8 | \begin{flushright} 9 | \begin{WINDOWS} 10 | \includegraphics[width=40mm]{windows-edition.eps} 11 | \end{WINDOWS} 12 | \begin{MAC} 13 | \includegraphics[width=40mm]{mac-edition.eps} 14 | \end{MAC} 15 | \begin{LINUX} 16 | \includegraphics[width=40mm]{linux-edition.eps} 17 | \end{LINUX} 18 | \end{flushright} 19 | \end{titlepage} 20 | \end{FRONTCOVER} 21 | 22 | \noindent 23 | \textsf{\emph{Snake Wrangling for Kids, Learning to Program with Python}}\\ 24 | by Jason R. Briggs\\ 25 | \\ 26 | Version 0.7.7 27 | \\\\ 28 | Copyright \copyright 2007.\\ 29 | \\ 30 | Cover art and illustrations by Nuthapitol C.\\ 31 | \\ 32 | \noindent 33 | \textsf{\emph{This book has been completely rewritten and updated, with new chapters (including developing graphical games), and new code examples. It also includes lots of fun programming puzzles to help cement the learning. Published by No Starch Press - available here: \href{http://nostarch.com/pythonforkids}{Python for Kids}. Also find more info \href{http://jasonrbriggs.com/python-for-kids/}{here}.}} 34 | \\ 35 | \\ 36 | \linebreak 37 | \noindent 38 | Website:\\ \href{http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids}{http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids}\\ 39 | \\ 40 | \noindent 41 | Thanks To:\\ 42 | Guido van Rossum (for benevelont dictatorship of the Python language), the members of the \href{http://www.python.org/community/sigs/current/edu-sig/}{Edu-Sig} mailing list (for helpful advice and commentary), author \href{http://www.davidbrin.com/}{David Brin} (the original \href{http://www.salon.com/tech/feature/2006/09/14/basic/}{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.\\ 43 | 44 | \noindent 45 | License:\\ 46 | \\ 47 | \includegraphics[width=40mm]{by-nc-sa.eps}\\ 48 | This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. To view a copy of this license, visit\\ \href{http://creativecommons.org/licenses/by-nc-sa/3.0/nz/}{http://creativecommons.org/licenses/by-nc-sa/3.0/nz/} or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.\\ 49 | 50 | \noindent 51 | Below is a summary of the license.\\ 52 | 53 | \noindent 54 | You are free: 55 | \begin{itemize} 56 | \item \textbf{to Share} — to copy, distribute and transmit the work 57 | \item \textbf{to Remix} — to adapt the work 58 | \end{itemize} 59 | \noindent 60 | Under the following conditions: 61 | \begin{description} 62 | \item[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). 63 | \item[Noncommercial.] You may not use this work for commercial purposes. 64 | \item[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. 65 | \end{description} 66 | 67 | \noindent 68 | For any reuse or distribution, you must make clear to others the license terms of this work.\\ 69 | 70 | \noindent 71 | Any of the above conditions can be waived if you get permission from the copyright holder.\\ 72 | 73 | \noindent 74 | Nothing in this license impairs or restricts the author's moral rights.\\ 75 | 76 | \vspace*{4cm} 77 | \begin{center} 78 | \includegraphics[width=5cm]{python-powered.eps} 79 | \end{center} 80 | 81 | \mainmatter 82 | 83 | \pagestyle{plain} 84 | 85 | \pagenumbering{roman} 86 | \tableofcontents -------------------------------------------------------------------------------- /en/license.txt: -------------------------------------------------------------------------------- 1 | Licence 2 | THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENCE ("CCPL" OR "LICENCE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORISED UNDER THIS LICENCE OR COPYRIGHT LAW IS PROHIBITED. BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENCE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS. 3 | This Creative Commons New Zealand Public Licence enables You (all capitalised terms defined below) to view, edit, modify, translate and distribute Works worldwide for Non-commercial purposes, under the terms of this licence, provided that You credit the Original Author. 4 | “The Licensor” 5 | and 6 | “You” 7 | agree as follows: 8 | 1. Definitions 9 | 10 | * “Adaptation” means any work created by the editing, modification, adaptation or translation of the Work in any media (however a work that constitutes a Collection will not be considered an Adaptation for the purpose of this Licence). For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronisation of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this Licence. 11 | * “Attribution means acknowledging all the parties who have contributed to and have rights in the Work or Collection under this Licence; and “Attribute” has a corresponding meaning. 12 | * “Collection” means the Work in its entirety in unmodified form along with one or more other separate and independent works, assembled into a collective whole. 13 | * “Licence” means this Creative Commons New Zealand Public Licence agreement. 14 | * “Licence Elements” means the following high-level licence attributes indicated in the title of this Licence: Attribution, Non-Commercial, Share-Alike. 15 | * “Licensor” means one or more legally recognised persons or entities offering the Work under the terms and conditions of this Licence. 16 | * “Non-Commercial” means “not primarily intended for or directed towards commercial advantage or private monetary compensation”. The exchange of the Work for other copyright works by means of digital file-sharing or otherwise shall not be considered to be intended for or directed towards commercial advantage or private monetary compensation, provided there is no payment of any monetary compensation in connection with the exchange of copyright works. 17 | * “Original Author” means the individual(s) or entity/ies who created the Work. 18 | * “Work” means the work protected by copyright which is offered under the terms of this Licence. 19 | * “You” means an individual or entity exercising rights under this Licence who has not previously violated the terms of this Licence with respect to the Work, or who has received express permission from the Licensor to exercise rights under this Licence despite a previous violation. 20 | * For the purpose of this Licence, when not inconsistent with the context, words in the singular number include the plural number. 21 | 22 | 2. Licence Terms 23 | 2.1 Subject to the terms of this agreement the Licensor hereby grants to You a worldwide, royalty-free, non-exclusive, Licence for Non-Commercial use and for the duration of copyright in the Work. 24 | You may: 25 | 26 | * copy the Work; 27 | * create one or more Adaptations. You must take reasonable steps to ensure any Adaptation clearly identifies that changes were made to the original Work; 28 | * incorporate the Work into one or more Collections; 29 | * copy Adaptations or the Work as incorporated in any Collection; and 30 | * publish, distribute, archive, perform or otherwise disseminate the Work, the Adaptation or the Work as incorporated in any Collection, to the public. 31 | 32 | All these rights may be exercised in any material form in any media whether now known or hereafter created. All these rights also include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. 33 | HOWEVER, 34 | You must not: 35 | 36 | * impose any terms on the use to be made of the Work, the Adaptation or the Work as incorporated in a Collection that alter or restrict the terms of this Licence or any rights granted under it or have the effect or intent of restricting the ability to exercise those rights; 37 | * impose any digital rights management technology on the Work, the Adaptation or the Work as incorporated in a Collection that alters or restricts the terms of this Licence or any rights granted under it or has the effect or intent of restricting the ability to exercise those rights; 38 | * sublicense the Work; 39 | * falsely Attribute the Work to someone other than the Original Author; 40 | * subject the Work to any derogatory treatment as defined in the Copyright Act 1994 provided that if the Licensor is the Original Author the Licensor will not enforce this sub-clause to the extent necessary to enable You to reasonably exercise Your right under clause 2.1 to make Adaptations but not otherwise. 41 | 42 | FINALLY, 43 | You must: 44 | 45 | * make reference to this Licence (by Uniform Resource Identifier (URI), spoken word or as appropriate to the media used) on all copies of the Work, Adaptations and Collections published, distributed, performed or otherwise disseminated or made available to the public by You; 46 | * recognise the Licensor's / Original Author's right of Attribution (right to be identified) in any Work, Adaptation and Collection that You publish, distribute, perform or otherwise disseminate to the public and ensure that You credit the Licensor / Original Author as appropriate to the media used. You will however remove such a credit if requested by the Licensor/Original Author; 47 | * not assert or imply any connection with sponsorship or endorsement by the Original Author or Licensor of You or Your use of the Work, without the separate, express prior written permission of the Original Author or Licensor; and 48 | * to the extent reasonably practicable, keep intact all notices that refer to this Licence, in particular the URI, if any, that the Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work. 49 | 50 | Additional Provisions 51 | 2.2. Further licence from the Licensor 52 | Each time You publish, distribute, perform or otherwise disseminate 53 | 54 | * the Work; or 55 | * any Adaptation; or 56 | * the Work as incorporated in a Collection 57 | 58 | the Licensor agrees to offer to the relevant third party making use of the Work (“User”) (in any of the alternatives set out above) a licence to use the Work on the same terms and conditions as granted to You hereunder. 59 | 2.3. Further licence from You 60 | Each time You publish, distribute, perform or otherwise disseminate 61 | 62 | * an Adaptation; or 63 | * an Adaptation as incorporated in a Collection 64 | 65 | You agree to offer to the User (in either of the alternatives set out above) a licence to use the Adaptation on any of the following premises: 66 | 67 | * a licence on the same terms and conditions as the licence granted to You hereunder; or 68 | * a later version of the licence granted to You hereunder with the same Licence Elements; or 69 | * any other Creative Commons licence (whether the Unported or a jurisdiction licence) with the same Licence Elements. 70 | 71 | 2.4. This Licence does not affect any rights that the User may have under any applicable law, including fair use, fair dealing or any other legally recognised limitation or exception to copyright infringement. 72 | 2.5. All rights not expressly granted by the Licensor are hereby reserved, including but not limited to, the exclusive right to collect, whether individually or via a licensing body, such as a collecting society, royalties for any use of the Work which results in commercial advantage or private monetary compensation. 73 | 2.6. The Licensor waives the right to collect royalties, whether individually or via a licensing body such as a collecting society, for any use of the Work which does not result in commercial advantage or private monetary compensation. 74 | 2.7. If the Licensor is the Original Author the Licensor waives its moral right to object to derogatory treatments of the Work to the extent necessary to enable You to reasonably exercise Your right under this Licence to make Adaptations but not otherwise. If the Licensor is not the Original Author the Work will still be subject to the moral rights of the Original Author. 75 | 3. Warranties and Disclaimer 76 | Except as required by law or as otherwise agreed in writing between the parties, the Work is licensed by the Licensor on an "as is" and "as available" basis and without any warranty of any kind, either express or implied. 77 | 4. Limit of Liability 78 | Subject to any liability which may not be excluded or limited by law the Licensor shall not be liable on any legal basis (including without limitation negligence) and hereby expressly excludes all liability for loss or damage howsoever and whenever caused to You. 79 | 5. Termination 80 | The rights granted to You under this Licence shall terminate automatically upon any breach by You of the terms of this Licence. Individuals or entities who have received Adaptations or Collections from You under this Licence, however, will not have their Licences terminated provided such individuals or entities remain in full compliance with those Licences. Clauses 1, 3, 4, 5 and 6 shall survive any termination of this Licence. 81 | 6. General 82 | 6.1. The validity or enforceability of the remaining terms of this agreement is not affected by the holding of any provision of it to be invalid or unenforceable. 83 | 6.2. This Licence constitutes the entire Licence Agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. The Licensor shall not be bound by any additional provisions that may appear in any communication in any form. 84 | 6.3. A person who is not a party to this Licence shall have no rights under the Contracts (Privity) Act 1982 to enforce any of its terms. 85 | 7. On the role of Creative Commons 86 | 7.1. Creative Commons does not authorise either the Licensor or the User to use the trade mark “Creative Commons” or any related trade mark, including the Creative Commons logo, except to indicate that the Work is licensed under a Creative Commons Licence. Any permitted use has to be in compliance with the Creative Commons trade mark usage guidelines at the time of use of the Creative Commons trade mark. These guidelines may be found on the Creative Commons website or be otherwise available upon request from time to time. For the avoidance of doubt this trade mark restriction does not form part of this Licence. 87 | 7.2. Creative Commons Corporation does not profit financially from its role in providing this Licence and will not investigate the claims of any Licensor or user of the Licence. 88 | 7.3. One of the conditions that Creative Commons Corporation requires of the Licensor and You is an acknowledgement of its limited role and agreement by all who use the Licence that the Corporation is not responsible to anyone for the statements and actions of You or the Licensor or anyone else attempting to use or using this Licence. 89 | 7.4. Creative Commons Corporation is not a party to this Licence, and makes no warranty whatsoever in connection to the Work or in connection to the Licence, and in all events is not liable for any loss or damage resulting from the Licensor's or Your reliance on this Licence or on its enforceability. 90 | 7.5. USE OF THIS LICENCE MEANS THAT YOU AND THE LICENSOR EACH ACCEPTS THESE CONDITIONS IN SECTION 7.1, 7.2, 7.3, 7.4 AND EACH ACKNOWLEDGES CREATIVE COMMONS CORPORATION'S VERY LIMITED ROLE AS A FACILITATOR OF THE LICENCE FROM THE LICENSOR TO YOU. 91 | Creative Commons Notice 92 | Creative Commons is not a party to this Licence, and makes no warranty whatsoever in connection with the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this Licence. Notwithstanding the foregoing two (2) sentences, if Creative Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations of Licensor. 93 | Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL, Creative Commons does not authorise the use by either party of the trademark "Creative Commons" or any related trademark or logo of Creative Commons without the prior written consent of Creative Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark usage guidelines, as may be published on its website or otherwise made available upon request from time to time. For the avoidance of doubt, this trademark restriction does not form part of this Licence. 94 | Creative Commons may be contacted at http://creativecommons.org/. 95 | -------------------------------------------------------------------------------- /en/linux-edition.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: inkscape 0.45.1 3 | %%Pages: 1 4 | %%Orientation: Portrait 5 | %%BoundingBox: 63 591 461 675 6 | %%HiResBoundingBox: 63.143934 591.86855 460.97183 674.45141 7 | %%EndComments 8 | %%Page: 1 1 9 | 0 842 translate 10 | 0.8 -0.8 scale 11 | 0 0 0 setrgbcolor 12 | [] 0 setdash 13 | 1 setlinewidth 14 | 0 setlinejoin 15 | 0 setlinecap 16 | gsave [1 0 0 1 0 0] concat 17 | gsave 18 | 1 0 0 setrgbcolor 19 | newpath 20 | 149.26201 277.50327 moveto 21 | 178.37236 277.50327 lineto 22 | 178.37236 266.44255 lineto 23 | 175.21215 266.44255 lineto 24 | 174.17901 273.73533 lineto 25 | 173.32818 274.7077 lineto 26 | 159.59345 274.7077 lineto 27 | 159.59345 240.37087 lineto 28 | 160.62659 239.52004 lineto 29 | 164.09066 239.1554 lineto 30 | 164.09066 236.72448 lineto 31 | 149.26201 236.72448 lineto 32 | 149.26201 239.1554 lineto 33 | 153.09072 239.52004 lineto 34 | 154.12387 240.37087 lineto 35 | 154.12387 273.85688 lineto 36 | 153.09072 274.7077 lineto 37 | 149.26201 275.01157 lineto 38 | 149.26201 277.50327 lineto 39 | fill 40 | grestore 41 | gsave 42 | 1 0 0 setrgbcolor 43 | newpath 44 | 188.55376 234.47587 moveto 45 | 186.60902 234.47587 185.02892 235.9952 185.02892 238.00071 curveto 46 | 185.02892 239.94545 186.60902 241.46478 188.55376 241.46478 curveto 47 | 190.4985 241.46478 192.0786 239.94545 192.0786 238.00071 curveto 48 | 192.0786 236.05598 190.4985 234.47587 188.55376 234.47587 curveto 49 | 188.31067 247.96751 moveto 50 | 181.32175 250.15535 lineto 51 | 181.32175 252.03931 lineto 52 | 185.57587 252.03931 lineto 53 | 185.57587 274.0392 lineto 54 | 184.54273 275.01157 lineto 55 | 181.32175 275.31543 lineto 56 | 181.32175 277.50327 lineto 57 | 194.99571 277.50327 lineto 58 | 194.99571 275.31543 lineto 59 | 191.71396 275.01157 lineto 60 | 190.62005 274.0392 lineto 61 | 190.62005 247.96751 lineto 62 | 188.31067 247.96751 lineto 63 | fill 64 | grestore 65 | gsave 66 | 1 0 0 setrgbcolor 67 | newpath 68 | 197.99164 277.50327 moveto 69 | 211.30096 277.50327 lineto 70 | 211.30096 275.31543 lineto 71 | 208.38385 275.01157 lineto 72 | 207.35071 274.0392 lineto 73 | 207.35071 253.68019 lineto 74 | 209.96395 252.34318 212.21256 251.67467 214.1573 251.67467 curveto 75 | 218.65451 251.67467 220.29539 253.49787 220.29539 257.93431 curveto 76 | 220.29539 274.0392 lineto 77 | 219.26224 275.01157 lineto 78 | 216.34513 275.31543 lineto 79 | 216.34513 277.50327 lineto 80 | 229.65445 277.50327 lineto 81 | 229.65445 275.31543 lineto 82 | 226.3727 275.01157 lineto 83 | 225.33956 274.0392 lineto 84 | 225.33956 256.90117 lineto 85 | 225.33956 250.82386 222.42244 247.66365 217.13518 247.66365 curveto 86 | 214.52194 247.66365 211.4225 249.06143 207.35071 251.31004 curveto 87 | 207.35071 247.96751 lineto 88 | 205.04133 247.96751 lineto 89 | 197.99164 250.15535 lineto 90 | 197.99164 252.03931 lineto 91 | 202.30653 252.03931 lineto 92 | 202.30653 274.0392 lineto 93 | 201.27339 275.01157 lineto 94 | 197.99164 275.31543 lineto 95 | 197.99164 277.50327 lineto 96 | fill 97 | grestore 98 | gsave 99 | 1 0 0 setrgbcolor 100 | newpath 101 | 239.33923 247.66365 moveto 102 | 232.28954 249.91225 lineto 103 | 232.28954 251.79622 lineto 104 | 236.60444 251.79622 lineto 105 | 236.60444 268.8127 lineto 106 | 236.60444 274.89001 239.52155 278.111 244.74804 278.111 curveto 107 | 247.72592 278.111 250.94691 276.71321 254.59329 274.09997 curveto 108 | 254.59329 277.50327 lineto 109 | 263.58772 277.50327 lineto 110 | 263.58772 275.31543 lineto 111 | 260.73138 275.01157 lineto 112 | 259.63746 274.0392 lineto 113 | 259.63746 247.66365 lineto 114 | 257.32808 247.66365 lineto 115 | 250.2784 249.91225 lineto 116 | 250.2784 251.79622 lineto 117 | 254.59329 251.79622 lineto 118 | 254.59329 272.39832 lineto 119 | 252.1016 273.61378 249.79221 274.22151 247.54361 274.22151 curveto 120 | 243.47181 274.22151 241.64861 272.15522 241.64861 267.77956 curveto 121 | 241.64861 247.66365 lineto 122 | 239.33923 247.66365 lineto 123 | fill 124 | grestore 125 | gsave 126 | 1 0 0 setrgbcolor 127 | newpath 128 | 266.34434 248.27138 moveto 129 | 266.34434 250.51998 lineto 130 | 270.05151 251.18849 lineto 131 | 278.19511 263.03925 lineto 132 | 269.44377 274.76847 lineto 133 | 265.97971 275.25466 lineto 134 | 265.97971 277.50327 lineto 135 | 277.46583 277.50327 lineto 136 | 277.46583 275.25466 lineto 137 | 274.00176 274.82925 lineto 138 | 273.6979 274.09997 lineto 139 | 279.89676 265.28786 lineto 140 | 285.54866 274.34306 lineto 141 | 285.2448 274.82925 lineto 142 | 282.69232 275.25466 lineto 143 | 282.69232 277.50327 lineto 144 | 295.637 277.50327 lineto 145 | 295.637 275.25466 lineto 146 | 291.99062 274.76847 lineto 147 | 283.05696 261.76302 lineto 148 | 291.07902 251.12772 lineto 149 | 294.48231 250.51998 lineto 150 | 294.48231 248.27138 lineto 151 | 283.54315 248.27138 lineto 152 | 283.54315 250.51998 lineto 153 | 286.46026 250.88462 lineto 154 | 286.94644 251.67467 lineto 155 | 281.41609 259.45364 lineto 156 | 276.31114 251.49235 lineto 157 | 276.61501 250.88462 lineto 158 | 279.41057 250.51998 lineto 159 | 279.41057 248.27138 lineto 160 | 266.34434 248.27138 lineto 161 | fill 162 | grestore 163 | gsave 164 | 1 0 0 setrgbcolor 165 | newpath 166 | fill 167 | grestore 168 | gsave 169 | 1 0 0 setrgbcolor 170 | newpath 171 | 314.73498 277.50327 moveto 172 | 346.03315 277.50327 lineto 173 | 346.03315 267.59724 lineto 174 | 342.87295 267.59724 lineto 175 | 341.8398 273.73533 lineto 176 | 340.98898 274.7077 lineto 177 | 324.70177 274.7077 lineto 178 | 324.70177 257.69122 lineto 179 | 334.66857 257.69122 lineto 180 | 335.51939 258.60281 lineto 181 | 336.12713 262.97848 lineto 182 | 338.98346 262.97848 lineto 183 | 338.98346 249.60839 lineto 184 | 336.12713 249.60839 lineto 185 | 335.51939 254.04483 lineto 186 | 334.66857 254.89565 lineto 187 | 324.70177 254.89565 lineto 188 | 324.70177 239.52004 lineto 189 | 338.74037 239.52004 lineto 190 | 339.5912 240.43164 lineto 191 | 340.44202 245.59736 lineto 192 | 343.84532 245.59736 lineto 193 | 343.84532 236.72448 lineto 194 | 314.73498 236.72448 lineto 195 | 314.73498 239.1554 lineto 196 | 318.19905 239.52004 lineto 197 | 319.23219 240.37087 lineto 198 | 319.23219 273.85688 lineto 199 | 318.19905 274.7077 lineto 200 | 314.73498 275.01157 lineto 201 | 314.73498 277.50327 lineto 202 | fill 203 | grestore 204 | gsave 205 | 1 0 0 setrgbcolor 206 | newpath 207 | 371.02136 236.84602 moveto 208 | 371.02136 248.27138 lineto 209 | 369.13739 247.84597 367.31419 247.60287 365.61255 247.60287 curveto 210 | 356.37504 247.60287 349.93307 254.10561 349.93307 263.82931 curveto 211 | 349.93307 272.33754 355.03802 278.05022 361.66229 278.05022 curveto 212 | 365.00481 278.05022 367.92193 276.83476 371.02136 274.34306 curveto 213 | 371.02136 277.50327 lineto 214 | 380.01578 277.50327 lineto 215 | 380.01578 275.31543 lineto 216 | 377.09867 275.01157 lineto 217 | 376.06553 274.0392 lineto 218 | 376.06553 232.77422 lineto 219 | 373.75615 232.77422 lineto 220 | 366.34182 234.96206 lineto 221 | 366.34182 236.84602 lineto 222 | 371.02136 236.84602 lineto 223 | 371.02136 272.09445 moveto 224 | 368.77275 273.49224 366.58492 274.22151 364.39708 274.22151 curveto 225 | 358.92751 274.22151 355.28111 269.90661 355.28111 262.79616 curveto 226 | 355.28111 255.19953 359.53524 250.27689 365.67332 250.27689 curveto 227 | 367.13187 250.27689 368.95507 250.64153 371.02136 251.24926 curveto 228 | 371.02136 272.09445 lineto 229 | fill 230 | grestore 231 | gsave 232 | 1 0 0 setrgbcolor 233 | newpath 234 | 391.40791 234.47587 moveto 235 | 389.46317 234.47587 387.88307 235.9952 387.88307 238.00071 curveto 236 | 387.88307 239.94545 389.46317 241.46478 391.40791 241.46478 curveto 237 | 393.35265 241.46478 394.93275 239.94545 394.93275 238.00071 curveto 238 | 394.93275 236.05598 393.35265 234.47587 391.40791 234.47587 curveto 239 | 391.16482 247.96751 moveto 240 | 384.1759 250.15535 lineto 241 | 384.1759 252.03931 lineto 242 | 388.43002 252.03931 lineto 243 | 388.43002 274.0392 lineto 244 | 387.39688 275.01157 lineto 245 | 384.1759 275.31543 lineto 246 | 384.1759 277.50327 lineto 247 | 397.84986 277.50327 lineto 248 | 397.84986 275.31543 lineto 249 | 394.56811 275.01157 lineto 250 | 393.4742 274.0392 lineto 251 | 393.4742 247.96751 lineto 252 | 391.16482 247.96751 lineto 253 | fill 254 | grestore 255 | gsave 256 | 1 0 0 setrgbcolor 257 | newpath 258 | 404.37062 251.91777 moveto 259 | 404.37062 271.5475 lineto 260 | 404.37062 275.86239 405.64686 277.68558 410.69103 277.68558 curveto 261 | 413.06118 277.68558 415.79598 277.26017 418.65231 276.34858 curveto 262 | 418.65231 274.09997 lineto 263 | 417.25453 274.40383 415.85675 274.58615 414.45896 274.58615 curveto 264 | 410.20485 274.58615 409.41479 272.58064 409.41479 267.96188 curveto 265 | 409.41479 251.91777 lineto 266 | 418.65231 251.91777 lineto 267 | 418.65231 249.06143 lineto 268 | 409.41479 249.06143 lineto 269 | 409.41479 242.61947 lineto 270 | 407.16619 242.61947 lineto 271 | 404.55294 248.27138 lineto 272 | 400.54191 250.0338 lineto 273 | 400.54191 251.91777 lineto 274 | 404.37062 251.91777 lineto 275 | fill 276 | grestore 277 | gsave 278 | 1 0 0 setrgbcolor 279 | newpath 280 | 428.67894 234.47587 moveto 281 | 426.7342 234.47587 425.15409 235.9952 425.15409 238.00071 curveto 282 | 425.15409 239.94545 426.7342 241.46478 428.67894 241.46478 curveto 283 | 430.62367 241.46478 432.20378 239.94545 432.20378 238.00071 curveto 284 | 432.20378 236.05598 430.62367 234.47587 428.67894 234.47587 curveto 285 | 428.43584 247.96751 moveto 286 | 421.44693 250.15535 lineto 287 | 421.44693 252.03931 lineto 288 | 425.70105 252.03931 lineto 289 | 425.70105 274.0392 lineto 290 | 424.66791 275.01157 lineto 291 | 421.44693 275.31543 lineto 292 | 421.44693 277.50327 lineto 293 | 435.12089 277.50327 lineto 294 | 435.12089 275.31543 lineto 295 | 431.83914 275.01157 lineto 296 | 430.74522 274.0392 lineto 297 | 430.74522 247.96751 lineto 298 | 428.43584 247.96751 lineto 299 | fill 300 | grestore 301 | gsave 302 | 1 0 0 setrgbcolor 303 | newpath 304 | 452.6416 247.66365 moveto 305 | 444.43724 247.66365 438.54223 253.80174 438.54223 262.85693 curveto 306 | 438.54223 271.85135 444.49801 278.05022 452.6416 278.05022 curveto 307 | 460.7852 278.05022 466.80175 271.85135 466.80175 262.85693 curveto 308 | 466.80175 253.86252 460.84597 247.66365 452.6416 247.66365 curveto 309 | 452.6416 250.27689 moveto 310 | 457.56422 250.27689 461.08907 255.01721 461.08907 262.85693 curveto 311 | 461.08907 270.75744 457.56422 275.43698 452.6416 275.43698 curveto 312 | 447.77976 275.43698 444.25491 270.69666 444.25491 262.85693 curveto 313 | 444.25491 254.95643 447.71898 250.27689 452.6416 250.27689 curveto 314 | fill 315 | grestore 316 | gsave 317 | 1 0 0 setrgbcolor 318 | newpath 319 | 470.87735 277.50327 moveto 320 | 484.18667 277.50327 lineto 321 | 484.18667 275.31543 lineto 322 | 481.26956 275.01157 lineto 323 | 480.23641 274.0392 lineto 324 | 480.23641 253.68019 lineto 325 | 482.84966 252.34318 485.09827 251.67467 487.04301 251.67467 curveto 326 | 491.54022 251.67467 493.1811 253.49787 493.1811 257.93431 curveto 327 | 493.1811 274.0392 lineto 328 | 492.14795 275.01157 lineto 329 | 489.23084 275.31543 lineto 330 | 489.23084 277.50327 lineto 331 | 502.54016 277.50327 lineto 332 | 502.54016 275.31543 lineto 333 | 499.25841 275.01157 lineto 334 | 498.22527 274.0392 lineto 335 | 498.22527 256.90117 lineto 336 | 498.22527 250.82386 495.30815 247.66365 490.02089 247.66365 curveto 337 | 487.40765 247.66365 484.30821 249.06143 480.23641 251.31004 curveto 338 | 480.23641 247.96751 lineto 339 | 477.92703 247.96751 lineto 340 | 470.87735 250.15535 lineto 341 | 470.87735 252.03931 lineto 342 | 475.19224 252.03931 lineto 343 | 475.19224 274.0392 lineto 344 | 474.1591 275.01157 lineto 345 | 470.87735 275.31543 lineto 346 | 470.87735 277.50327 lineto 347 | fill 348 | grestore 349 | 1 0 0 setrgbcolor 350 | [] 0 setdash 351 | 11.458478 setlinewidth 352 | 1 setlinejoin 353 | 0 setlinecap 354 | newpath 355 | 114.67006 215.02716 moveto 356 | 540.47464 215.02716 lineto 357 | 557.10068 215.02716 570.48554 228.41202 570.48554 245.03807 curveto 358 | 570.48554 276.78635 lineto 359 | 570.48554 293.41239 557.10068 306.79726 540.47464 306.79726 curveto 360 | 114.67006 306.79726 lineto 361 | 98.044021 306.79726 84.659157 293.41239 84.659157 276.78635 curveto 362 | 84.659157 245.03807 lineto 363 | 84.659157 228.41202 98.044021 215.02716 114.67006 215.02716 curveto 364 | closepath 365 | stroke 366 | grestore 367 | showpage 368 | %%EOF 369 | -------------------------------------------------------------------------------- /en/longdiv.sty: -------------------------------------------------------------------------------- 1 | % 2 | % longdiv[ision].sty 3 | % 4 | \newcount\gpten % (global) power-of-ten -- tells which digit we are doing 5 | \newcount\rtot % running total -- remainder so far 6 | \newcount\scratch 7 | 8 | \def\longdiv#1#2{% long division: #1/#2; integers only, gives integer quotient and remainder 9 | \vtop{\offinterlineskip 10 | \setbox\strutbox\hbox{\vrule height 2.1ex depth .5ex width0ex}% 11 | \def\showdig{$\underline{\the\scratch\strut}$\cr\the\rtot\strut\cr 12 | \noalign{\kern-.2ex}}% 13 | \global\rtot=#1\relax 14 | \count0=\rtot\divide\count0by#2\edef\quotient{\the\count0}%\show\quotient 15 | % make list macro out of digits in quotient: 16 | \def\temp##1{\ifx##1\temp\else \noexpand\dodig ##1\expandafter\temp\fi}% 17 | \edef\routine{\expandafter\temp\quotient\temp}% 18 | % process list to give power-of-ten: 19 | \def\dodig##1{\global\multiply\gpten by10\relax}\global\gpten=1\relax\routine 20 | % to display effect of one digit in quotient (zero ignored): 21 | \def\dodig##1{\global\divide\gpten by10\relax 22 | \scratch =\gpten 23 | \multiply\scratch by##1\relax 24 | \multiply\scratch by#2\relax 25 | \global\advance\rtot-\scratch \relax 26 | \ifnum\scratch>0 \showdig \fi % must hide \cr in a macro to skip it 27 | }% 28 | \tabskip=0pt 29 | \halign{\hfil##\cr % \halign for entire division problem 30 | $\quotient$\strut\cr 31 | #2\kern.25em\smash{\raise.33ex\hbox{$\big)$}}$\mkern-8mu 32 | \overline{\enspace\the\rtot\strut}$\cr\noalign{\kern-.2ex} 33 | \routine \cr % do each digit in quotient 34 | }}} 35 | \endinput 36 | % 37 | % TeX sample 38 | % 39 | \noindent Here are some long division problems 40 | 41 | \indent 42 | \longdiv{12345}{13} 43 | \longdiv{123}{1234} 44 | \longdiv{31415926}{2} 45 | \longdiv{81}{3} 46 | \longdiv{1132}{99} 47 | \bye 48 | % -------------------------------------------------------------------------------- /en/mac-edition.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: inkscape 0.45.1 3 | %%Pages: 1 4 | %%Orientation: Portrait 5 | %%BoundingBox: 63 459 461 543 6 | %%HiResBoundingBox: 63.143934 459.47167 460.97183 542.05453 7 | %%EndComments 8 | %%Page: 1 1 9 | 0 842 translate 10 | 0.8 -0.8 scale 11 | 0 0 0 setrgbcolor 12 | [] 0 setdash 13 | 1 setlinewidth 14 | 0 setlinejoin 15 | 0 setlinecap 16 | gsave [1 0 0 1 0 0] concat 17 | gsave 18 | 1 0 0 setrgbcolor 19 | newpath 20 | 168.28686 442.99936 moveto 21 | 181.11 442.99936 lineto 22 | 181.11 440.50766 lineto 23 | 177.40283 440.02147 lineto 24 | 176.30892 438.86678 lineto 25 | 176.30892 405.68464 lineto 26 | 190.1652 442.99936 lineto 27 | 192.77844 442.99936 lineto 28 | 207.18168 405.07691 lineto 29 | 207.18168 439.35297 lineto 30 | 206.57395 440.20379 lineto 31 | 202.56292 440.50766 lineto 32 | 202.56292 442.99936 lineto 33 | 217.0877 442.99936 lineto 34 | 217.0877 440.50766 lineto 35 | 213.259 440.20379 lineto 36 | 212.52972 439.35297 lineto 37 | 212.52972 405.86696 lineto 38 | 213.259 405.01614 lineto 39 | 217.0877 404.6515 lineto 40 | 217.0877 402.22057 lineto 41 | 204.08225 402.22057 lineto 42 | 204.08225 404.10454 lineto 43 | 192.53535 434.36957 lineto 44 | 181.11 403.86145 lineto 45 | 181.11 402.22057 lineto 46 | 168.22609 402.22057 lineto 47 | 168.22609 404.6515 lineto 48 | 172.23712 405.01614 lineto 49 | 173.02717 405.86696 lineto 50 | 173.02717 438.86678 lineto 51 | 171.93325 440.02147 lineto 52 | 168.28686 440.50766 lineto 53 | 168.28686 442.99936 lineto 54 | fill 55 | grestore 56 | gsave 57 | 1 0 0 setrgbcolor 58 | newpath 59 | 239.28415 439.47452 moveto 60 | 240.0742 442.99936 lineto 61 | 248.64322 442.99936 lineto 62 | 248.64322 440.81153 lineto 63 | 245.42224 440.50766 lineto 64 | 244.32832 439.53529 lineto 65 | 244.32832 421.91107 lineto 66 | 244.32832 415.77299 241.6543 413.15974 235.27312 413.15974 curveto 67 | 227.61571 413.15974 222.99694 416.31995 222.99694 420.02711 curveto 68 | 222.99694 421.48566 223.48313 421.91107 224.88091 421.91107 curveto 69 | 229.07426 421.91107 lineto 70 | 229.07426 416.80613 lineto 71 | 230.71513 416.13763 232.17369 415.83376 233.69302 415.83376 curveto 72 | 238.06868 415.83376 239.28415 417.83928 239.28415 422.64035 curveto 73 | 239.28415 424.58509 lineto 74 | 227.12953 427.5022 221.53839 429.32541 221.53839 435.64581 curveto 75 | 221.53839 440.20379 224.51628 443.42477 229.31735 443.42477 curveto 76 | 232.23446 443.42477 235.45545 442.08776 239.28415 439.47452 curveto 77 | 239.28415 437.40823 moveto 78 | 236.2455 439.17065 233.75379 440.14302 231.74828 440.14302 curveto 79 | 228.70962 440.14302 226.88643 438.1375 226.88643 435.15962 curveto 80 | 226.88643 430.72319 230.71514 429.0823 239.28415 426.71215 curveto 81 | 239.28415 437.40823 lineto 82 | fill 83 | grestore 84 | gsave 85 | 1 0 0 setrgbcolor 86 | newpath 87 | 275.67587 440.44689 moveto 88 | 275.67587 437.28668 lineto 89 | 273.1234 438.98833 270.6317 439.83916 267.95768 439.83916 curveto 90 | 261.63728 439.83916 257.62625 435.40271 257.62625 427.92762 curveto 91 | 257.62625 420.27021 261.33341 415.59067 266.5599 415.59067 curveto 92 | 267.59304 415.59067 268.56542 415.89453 269.47701 416.44149 curveto 93 | 269.47701 421.42489 lineto 94 | 270.38861 422.03262 271.30021 422.33649 272.2118 422.33649 curveto 95 | 274.27809 422.33649 275.6151 421.06025 275.6151 419.11551 curveto 96 | 275.6151 415.59067 272.33334 413.15974 266.49913 413.15974 curveto 97 | 257.99089 413.15974 252.09589 419.29784 252.09589 428.35303 curveto 98 | 252.09589 437.34745 257.50471 443.42477 265.76985 443.42477 curveto 99 | 269.0516 443.42477 272.33335 442.39163 275.67587 440.44689 curveto 100 | fill 101 | grestore 102 | gsave 103 | 1 0 0 setrgbcolor 104 | newpath 105 | fill 106 | grestore 107 | gsave 108 | 1 0 0 setrgbcolor 109 | newpath 110 | 295.77089 442.99936 moveto 111 | 327.06907 442.99936 lineto 112 | 327.06907 433.09333 lineto 113 | 323.90887 433.09333 lineto 114 | 322.87572 439.23142 lineto 115 | 322.0249 440.20379 lineto 116 | 305.73769 440.20379 lineto 117 | 305.73769 423.18731 lineto 118 | 315.70449 423.18731 lineto 119 | 316.55531 424.09891 lineto 120 | 317.16305 428.47458 lineto 121 | 320.01938 428.47458 lineto 122 | 320.01938 415.10448 lineto 123 | 317.16305 415.10448 lineto 124 | 316.55531 419.54092 lineto 125 | 315.70449 420.39175 lineto 126 | 305.73769 420.39175 lineto 127 | 305.73769 405.01614 lineto 128 | 319.77629 405.01614 lineto 129 | 320.62712 405.92773 lineto 130 | 321.47794 411.09345 lineto 131 | 324.88124 411.09345 lineto 132 | 324.88124 402.22057 lineto 133 | 295.77089 402.22057 lineto 134 | 295.77089 404.6515 lineto 135 | 299.23496 405.01614 lineto 136 | 300.26811 405.86696 lineto 137 | 300.26811 439.35297 lineto 138 | 299.23496 440.20379 lineto 139 | 295.77089 440.50766 lineto 140 | 295.77089 442.99936 lineto 141 | fill 142 | grestore 143 | gsave 144 | 1 0 0 setrgbcolor 145 | newpath 146 | 352.05728 402.34212 moveto 147 | 352.05728 413.76747 lineto 148 | 350.17331 413.34206 348.35011 413.09897 346.64847 413.09897 curveto 149 | 337.41096 413.09897 330.96899 419.6017 330.96899 429.3254 curveto 150 | 330.96899 437.83363 336.07394 443.54632 342.69821 443.54632 curveto 151 | 346.04073 443.54632 348.95785 442.33085 352.05728 439.83916 curveto 152 | 352.05728 442.99936 lineto 153 | 361.0517 442.99936 lineto 154 | 361.0517 440.81153 lineto 155 | 358.13459 440.50766 lineto 156 | 357.10145 439.53529 lineto 157 | 357.10145 398.27032 lineto 158 | 354.79207 398.27032 lineto 159 | 347.37774 400.45815 lineto 160 | 347.37774 402.34212 lineto 161 | 352.05728 402.34212 lineto 162 | 352.05728 437.59055 moveto 163 | 349.80867 438.98833 347.62083 439.71761 345.433 439.71761 curveto 164 | 339.96342 439.71761 336.31703 435.40271 336.31703 428.29226 curveto 165 | 336.31703 420.69562 340.57116 415.77299 346.70924 415.77299 curveto 166 | 348.16779 415.77299 349.99099 416.13763 352.05728 416.74536 curveto 167 | 352.05728 437.59055 lineto 168 | fill 169 | grestore 170 | gsave 171 | 1 0 0 setrgbcolor 172 | newpath 173 | 372.44383 399.97197 moveto 174 | 370.49909 399.97197 368.91899 401.4913 368.91899 403.49681 curveto 175 | 368.91899 405.44155 370.49909 406.96088 372.44383 406.96088 curveto 176 | 374.38857 406.96088 375.96867 405.44155 375.96867 403.49681 curveto 177 | 375.96867 401.55207 374.38857 399.97197 372.44383 399.97197 curveto 178 | 372.20074 413.46361 moveto 179 | 365.21182 415.65144 lineto 180 | 365.21182 417.53541 lineto 181 | 369.46594 417.53541 lineto 182 | 369.46594 439.53529 lineto 183 | 368.4328 440.50766 lineto 184 | 365.21182 440.81153 lineto 185 | 365.21182 442.99936 lineto 186 | 378.88578 442.99936 lineto 187 | 378.88578 440.81153 lineto 188 | 375.60403 440.50766 lineto 189 | 374.51012 439.53529 lineto 190 | 374.51012 413.46361 lineto 191 | 372.20074 413.46361 lineto 192 | fill 193 | grestore 194 | gsave 195 | 1 0 0 setrgbcolor 196 | newpath 197 | 385.40656 417.41386 moveto 198 | 385.40656 437.04359 lineto 199 | 385.40656 441.35848 386.6828 443.18168 391.72696 443.18168 curveto 200 | 394.09711 443.18168 396.83191 442.75627 399.68825 441.84467 curveto 201 | 399.68825 439.59606 lineto 202 | 398.29047 439.89993 396.89268 440.08225 395.4949 440.08225 curveto 203 | 391.24078 440.08225 390.45073 438.07673 390.45073 433.45797 curveto 204 | 390.45073 417.41386 lineto 205 | 399.68825 417.41386 lineto 206 | 399.68825 414.55752 lineto 207 | 390.45073 414.55752 lineto 208 | 390.45073 408.11557 lineto 209 | 388.20212 408.11557 lineto 210 | 385.58887 413.76747 lineto 211 | 381.57785 415.52989 lineto 212 | 381.57785 417.41386 lineto 213 | 385.40656 417.41386 lineto 214 | fill 215 | grestore 216 | gsave 217 | 1 0 0 setrgbcolor 218 | newpath 219 | 409.71487 399.97197 moveto 220 | 407.77013 399.97197 406.19003 401.4913 406.19003 403.49681 curveto 221 | 406.19003 405.44155 407.77013 406.96088 409.71487 406.96088 curveto 222 | 411.65961 406.96088 413.23971 405.44155 413.23971 403.49681 curveto 223 | 413.23971 401.55207 411.65961 399.97197 409.71487 399.97197 curveto 224 | 409.47178 413.46361 moveto 225 | 402.48286 415.65144 lineto 226 | 402.48286 417.53541 lineto 227 | 406.73699 417.53541 lineto 228 | 406.73699 439.53529 lineto 229 | 405.70384 440.50766 lineto 230 | 402.48286 440.81153 lineto 231 | 402.48286 442.99936 lineto 232 | 416.15682 442.99936 lineto 233 | 416.15682 440.81153 lineto 234 | 412.87507 440.50766 lineto 235 | 411.78116 439.53529 lineto 236 | 411.78116 413.46361 lineto 237 | 409.47178 413.46361 lineto 238 | fill 239 | grestore 240 | gsave 241 | 1 0 0 setrgbcolor 242 | newpath 243 | 433.67754 413.15974 moveto 244 | 425.47317 413.15974 419.57817 419.29784 419.57817 428.35303 curveto 245 | 419.57817 437.34745 425.53394 443.54632 433.67754 443.54632 curveto 246 | 441.82113 443.54632 447.83768 437.34745 447.83768 428.35303 curveto 247 | 447.83768 419.35861 441.88191 413.15974 433.67754 413.15974 curveto 248 | 433.67754 415.77299 moveto 249 | 438.60016 415.77299 442.12501 420.5133 442.12501 428.35303 curveto 250 | 442.12501 436.25353 438.60016 440.93307 433.67754 440.93307 curveto 251 | 428.81569 440.93307 425.29084 436.19276 425.29084 428.35303 curveto 252 | 425.29084 420.45253 428.75492 415.77299 433.67754 415.77299 curveto 253 | fill 254 | grestore 255 | gsave 256 | 1 0 0 setrgbcolor 257 | newpath 258 | 451.91328 442.99936 moveto 259 | 465.2226 442.99936 lineto 260 | 465.2226 440.81153 lineto 261 | 462.30549 440.50766 lineto 262 | 461.27235 439.53529 lineto 263 | 461.27235 419.17628 lineto 264 | 463.88559 417.83927 466.1342 417.17077 468.07894 417.17077 curveto 265 | 472.57615 417.17077 474.21703 418.99397 474.21703 423.4304 curveto 266 | 474.21703 439.53529 lineto 267 | 473.18389 440.50766 lineto 268 | 470.26678 440.81153 lineto 269 | 470.26678 442.99936 lineto 270 | 483.5761 442.99936 lineto 271 | 483.5761 440.81153 lineto 272 | 480.29435 440.50766 lineto 273 | 479.2612 439.53529 lineto 274 | 479.2612 422.39726 lineto 275 | 479.2612 416.31995 476.34409 413.15974 471.05683 413.15974 curveto 276 | 468.44358 413.15974 465.34415 414.55752 461.27235 416.80613 curveto 277 | 461.27235 413.46361 lineto 278 | 458.96297 413.46361 lineto 279 | 451.91328 415.65144 lineto 280 | 451.91328 417.53541 lineto 281 | 456.22818 417.53541 lineto 282 | 456.22818 439.53529 lineto 283 | 455.19503 440.50766 lineto 284 | 451.91328 440.81153 lineto 285 | 451.91328 442.99936 lineto 286 | fill 287 | grestore 288 | 1 0 0 setrgbcolor 289 | [] 0 setdash 290 | 11.458478 setlinewidth 291 | 1 setlinejoin 292 | 0 setlinecap 293 | newpath 294 | 114.67006 380.52325 moveto 295 | 540.47464 380.52325 lineto 296 | 557.10068 380.52325 570.48554 393.90812 570.48554 410.53416 curveto 297 | 570.48554 442.28244 lineto 298 | 570.48554 458.90849 557.10068 472.29335 540.47464 472.29335 curveto 299 | 114.67006 472.29335 lineto 300 | 98.044021 472.29335 84.659157 458.90849 84.659157 442.28244 curveto 301 | 84.659157 410.53416 lineto 302 | 84.659157 393.90812 98.044021 380.52325 114.67006 380.52325 curveto 303 | closepath 304 | stroke 305 | grestore 306 | showpage 307 | %%EOF 308 | -------------------------------------------------------------------------------- /en/preface.tex: -------------------------------------------------------------------------------- 1 | % preface.tex 2 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 3 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 4 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 5 | 6 | 7 | \chapter*{Preface}\normalsize 8 | \addcontentsline{toc}{chapter}{Preface} 9 | \begin{center} 10 | {\em A Note to Parents...} 11 | \end{center} 12 | \pagestyle{plain} 13 | 14 | \noindent 15 | Dear Parental Unit or other Caregiver, 16 | 17 | In order for your child to get started with programming, you're going to need to install Python on your computer. This book has recently been updated to use Python 3.0--this latest version of Python is not compatible with earlier versions, so if you have an earlier version of Python installed, then you'll need to download an older release of the book. 18 | 19 | Installing Python is a fairly straight-forward task, but there are a few wrinkles depending upon what sort of Operating System you're using. If you've just bought a shiny new computer, have no idea what to do with it, and that previous statement has filled you with a severe case of the cold chills, you'll probably want to find someone to do this for you. Depending upon the state of your computer, and the speed of your internet connection, this could take anything from 15 minutes to a few hours. 20 | 21 | \begin{WINDOWS} 22 | 23 | \noindent 24 | First of all, go to \href{http://www.python.org}{www.python.org} and download the latest Windows installer for Python 3. At time of writing, this is: 25 | \begin{quote} 26 | \href{http://www.python.org/ftp/python/3.0.1/python-3.0.1.msi}{http://www.python.org/ftp/python/3.0.1/python-3.0.1.msi} 27 | \end{quote} 28 | Double-click the icon for the Windows installer (you do remember where you downloaded it to, don't you?), and then follow the instructions to install it in the default location (this is probably \emph{c:$\backslash$Python30} or something very similar). 29 | 30 | \end{WINDOWS} 31 | 32 | \begin{MAC} 33 | 34 | \noindent 35 | At time of writing, installing Python 3 on your Mac is a more complicated process than usual. At the moment, there are no one-click install packages available. There is information out there describing the installation process (here is a good \href{http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/}{page}), but the basic process is to download the source package and then build it yourself. This isn't as difficult as it sounds, but you will need to follow a few steps in the Terminal. If you find this too complicated, I recommend sticking with the \href{http://www.briggs.net.nz/log/wp-content/uploads/2008/03/swfk-mac.zip}{previous version} of this book. 36 | 37 | \noindent 38 | First of all, go to \href{www.python.org}{www.python.org} and download the Python source package. As of Dec 2008, the address for this download is: 39 | 40 | \noindent 41 | \href{http://www.python.org/ftp/python/3.0/Python-3.0.tar.bz2}{http://www.python.org/ftp/python/3.0/Python-3.0.tar.bz2} 42 | 43 | \noindent 44 | Start the Terminal application, and enter the following commands: 45 | 46 | \begin{listing} 47 | \begin{verbatim} 48 | $ cd ~/Downloads/Python-3.0/ 49 | $ ./configure --enable-framework MACOSX_DEPLOYMENT_TARGET=10.5 --with-universal-archs=all 50 | $ make && make test 51 | $ sudo make frameworkinstall 52 | \end{verbatim} 53 | \end{listing} 54 | 55 | \noindent 56 | The following steps may, or may not, be necessary. First of all type: 57 | 58 | \code{ls -la /Library/Frameworks/Python.framework/Versions/} 59 | 60 | \noindent 61 | In my case, there are only two directories shown: 62 | 63 | \begin{listing} 64 | \begin{verbatim} 65 | drwxr-xr-x 4 root admin 136 6 Dec 23:31 . 66 | drwxr-xr-x 6 root admin 204 6 Dec 23:31 .. 67 | drwxr-xr-x 9 root admin 306 6 Dec 23:32 3.0 68 | lrwxr-xr-x 1 root admin 3 6 Dec 23:31 Current -> 3.0 69 | \end{verbatim} 70 | \end{listing} 71 | 72 | \noindent 73 | If you have more than those two directories listed (for example)$\ldots$ 74 | 75 | \begin{listing} 76 | \begin{verbatim} 77 | drwxr-xr-x 4 root admin 136 6 Dec 23:31 . 78 | drwxr-xr-x 6 root admin 204 6 Dec 23:31 .. 79 | drwxr-xr-x 9 root admin 306 7 Nov 08:19 2.4 80 | drwxr-xr-x 9 root admin 306 22 Mar 23:32 2.5 81 | drwxr-xr-x 9 root admin 306 12 Dec 10:22 2.6 82 | drwxr-xr-x 9 root admin 306 6 Dec 23:31 3.0 83 | lrwxr-xr-x 1 root admin 3 6 Dec 23:31 Current -> 3.0 84 | \end{verbatim} 85 | \end{listing} 86 | 87 | \noindent 88 | $\ldots$then you may need to perform the following steps: 89 | 90 | \begin{listing} 91 | \begin{verbatim} 92 | $ cd /Library/Frameworks/Python.framework/Versions/ 93 | $ sudo rm Current 94 | $ sudo ln -s 2.5 Current 95 | \end{verbatim} 96 | \end{listing} 97 | 98 | Finally, you'll want to setup Python 3 as the default, for when your child opens the Terminal application. To do this you'll need to edit the path used by Terminal--start Terminal, and then enter the following command \code{pico ~/.bash\_profile}. This file may (or may not) exist already, and if it does, there may (or may not) already be a path set up. In any case, at the bottom of the file, add the following: 99 | 100 | \begin{listing} 101 | \begin{verbatim} 102 | export PATH="/Library/Frameworks/Python.framework/Versions/3.0/bin:${PATH}" 103 | \end{verbatim} 104 | \end{listing} 105 | 106 | Save your changes, by hitting CTRL+X, and typing Y to save. If you restart the Terminal app, and type \code{python}, with any luck, you should see something similar to the following: 107 | 108 | \begin{listing} 109 | \begin{verbatim} 110 | Python 3.0 (r30:67503, Dec 6 2008, 23:22:48) 111 | [GCC 4.0.1 (Apple Inc. build 5465)] on darwin 112 | Type "help", "copyright", "credits" or "license" for more information. 113 | >>> 114 | \end{verbatim} 115 | \end{listing} 116 | 117 | \end{MAC} 118 | 119 | \begin{LINUX} 120 | 121 | \noindent 122 | First of all, download and install the latest version of Python 3 for your distribution. Given the large number of Linux flavours, it's impossible to give exact details on installation for each---but chances are, if you're running Linux, you already know what you're doing anyway. In fact, you're probably insulted by the very idea of being told how to install$\ldots$anything 123 | 124 | \end{LINUX} 125 | 126 | \noindent 127 | \emph{\color{BrickRed}After installation$\ldots$} 128 | 129 | \noindent 130 | $\ldots$You might need to sit down next to your child for the first few chapters, but hopefully after a few examples, they should be batting your hands away from the keyboard to do it themselves. They should, at least, know how to use a text editor of some kind before they start (no, not a Word Processor, like Microsoft Word---a plain, old-fashioned text editor)---they should at least able to open and close files, create new text files and save what they're doing. Apart from that, this book will try to teach the basics from there. 131 | \\ 132 | \\ 133 | \noindent\\ 134 | Thanks for your time, and kind regards, 135 | \noindent\\ 136 | THE BOOK -------------------------------------------------------------------------------- /en/setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup, Command 2 | from distutils.spawn import find_executable, spawn 3 | from zipfile import ZipFile 4 | 5 | import os 6 | import re 7 | 8 | 9 | # 10 | # where to write target files 11 | # 12 | target_dir = 'target' 13 | 14 | # 15 | # 16 | # 17 | platforms = 'win', 'mac', 'linux' 18 | #platforms = 'win', 19 | 20 | # 21 | # find the executables to use in compiling the books 22 | # 23 | latex = find_executable('latex') 24 | makeindex = find_executable('makeindex') 25 | dvipdf = find_executable('dvipdf') 26 | 27 | # 28 | # Get the book version 29 | # 30 | s = open('frontmatter.tex').read() 31 | mat = re.compile(r'Version\s*(.*)').search(s) 32 | version = mat.group(1) 33 | 34 | if not os.path.exists(target_dir): 35 | os.mkdir(target_dir) 36 | 37 | class CleanCommand(Command): 38 | user_options = [ ] 39 | 40 | def initialize_options(self): 41 | self._clean_me = [ ] 42 | for root, dirs, files in os.walk(target_dir): 43 | for f in files: 44 | self._clean_me.append(os.path.join(root, f)) 45 | 46 | def finalize_options(self): 47 | pass 48 | 49 | def run(self): 50 | for clean_me in self._clean_me: 51 | try: 52 | os.unlink(clean_me) 53 | except: 54 | pass 55 | 56 | 57 | class LatexCommand(Command): 58 | user_options = [ ('cover=', 'c', 'include the cover in the output') ] 59 | 60 | def initialize_options(self): 61 | self.cover = 'include' 62 | 63 | def finalize_options(self): 64 | pass 65 | 66 | def run(self): 67 | for platform in platforms: 68 | s = open('swfk.tex.pre').read() 69 | if self.cover == 'include': 70 | s = s.replace('@FRONTCOVER_INC@', 'include') 71 | fname_suffix = '' 72 | else: 73 | s = s.replace('@FRONTCOVER_INC@', 'exclude') 74 | fname_suffix = '-nc' 75 | 76 | if platform == 'win': 77 | s = s.replace('@WINDOWS_INC@', 'include') 78 | s = s.replace('@MAC_INC@', 'exclude') 79 | s = s.replace('@LINUX_INC@', 'exclude') 80 | elif platform == 'mac': 81 | s = s.replace('@WINDOWS_INC@', 'exclude') 82 | s = s.replace('@MAC_INC@', 'include') 83 | s = s.replace('@LINUX_INC@', 'exclude') 84 | elif platform == 'linux': 85 | s = s.replace('@WINDOWS_INC@', 'exclude') 86 | s = s.replace('@MAC_INC@', 'exclude') 87 | s = s.replace('@LINUX_INC@', 'include') 88 | else: 89 | raise RuntimeError('unrecognised platform %s' % platform) 90 | 91 | swfk_tex = open('swfk.tex', 'w') 92 | swfk_tex.write(s) 93 | swfk_tex.close() 94 | 95 | tex = 'swfk.tex' 96 | spawn([latex, '--output-directory=%s' % target_dir, tex]) 97 | 98 | spawn([makeindex, '%s/swfk.idx' % target_dir]) 99 | spawn([latex, '--output-directory=%s' % target_dir, tex]) 100 | 101 | pdf = '%s/swfk-%s-%s%s.pdf' % (target_dir, platform, version, fname_suffix) 102 | spawn([dvipdf, '%s/swfk.dvi' % target_dir, pdf]) 103 | 104 | zf = ZipFile('%s/swfk-%s-%s%s.zip' % (target_dir, platform, version, fname_suffix), 'w') 105 | zf.write(pdf) 106 | zf.close() 107 | 108 | 109 | setup( 110 | name = 'SWFK', 111 | version = '1.00', 112 | description = 'Snake Wrangling For Kids', 113 | 114 | author = 'Jason R Briggs', 115 | author_email = 'jason@briggs.net.nz', 116 | 117 | cmdclass = { 'clean': CleanCommand, 'build' : LatexCommand } 118 | 119 | ) 120 | -------------------------------------------------------------------------------- /en/swfk.tex.pre: -------------------------------------------------------------------------------- 1 | 2 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 3 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 4 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 5 | 6 | \documentclass[12pt,leqno,a4paper]{book} 7 | \usepackage[dvips]{graphicx} 8 | \usepackage[usenames]{color} 9 | \usepackage[colorlinks,pdfauthor={Jason R Briggs},pdftitle={Snake Wrangling for Kids - Learning to Program with Python},pdfsubject={Programming for Kids},pdfkeywords={python,kids,programming}]{hyperref} 10 | \usepackage{longdiv} 11 | \usepackage{makeidx} 12 | \usepackage{versions} 13 | \usepackage[absolute]{textpos} 14 | \usepackage{wrapfig} 15 | \usepackage{eso-pic} 16 | 17 | \parindent 1cm 18 | \parskip 0.2cm 19 | \topmargin 0.2cm 20 | \oddsidemargin 1cm 21 | \evensidemargin 0.5cm 22 | \textwidth 15cm 23 | \textheight 21cm 24 | 25 | \definecolor{PaleBlue}{rgb}{0.95,0.95,1} 26 | 27 | \newenvironment{listing} 28 | {\begin{list}{}{\setlength{\leftmargin}{1em}}\item\footnotesize\samepage} 29 | {\end{list}} 30 | 31 | \newenvironment{listingignore} 32 | {\begin{list}{}{\setlength{\leftmargin}{1em}}\item\footnotesize\samepage} 33 | {\end{list}} 34 | 35 | \newcommand{\code}{\textcolor{OliveGreen}\bfseries} 36 | 37 | \@FRONTCOVER_INC@version{FRONTCOVER} 38 | \@WINDOWS_INC@version{WINDOWS} 39 | \@MAC_INC@version{MAC} 40 | \@LINUX_INC@version{LINUX} 41 | 42 | \title{Snake Wrangling for Kids - Learning to Program with Python} 43 | \author{Jason R Briggs} 44 | 45 | \makeindex 46 | 47 | \begin{document} 48 | 49 | \include{frontmatter} 50 | 51 | \include{preface} 52 | 53 | \pagestyle{headings} 54 | \pagenumbering{arabic} 55 | 56 | \include{ch1} 57 | \include{ch2} 58 | \include{ch3} 59 | \include{ch4} 60 | \include{ch5} 61 | \include{ch6} 62 | \include{ch7} 63 | \include{ch8} 64 | \include{ch9} 65 | \include{ch10} 66 | 67 | \appendix 68 | \include{appendixa} 69 | \include{appendixb} 70 | \include{appendixc} 71 | \include{appendixd} 72 | 73 | \printindex 74 | 75 | \end{document} 76 | -------------------------------------------------------------------------------- /en/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/en/test.gif -------------------------------------------------------------------------------- /en/test.txt: -------------------------------------------------------------------------------- 1 | test 2 | -------------------------------------------------------------------------------- /en/textedit-icon.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: GIMP PostScript file plugin V 1.17 by Peter Kirchgessner 3 | %%Title: textedit-icon.eps 4 | %%CreationDate: Sat Nov 17 17:39:48 2007 5 | %%DocumentData: Clean7Bit 6 | %%LanguageLevel: 2 7 | %%Pages: 1 8 | %%BoundingBox: 14 14 49 49 9 | %%EndComments 10 | %%BeginProlog 11 | % Use own dictionary to avoid conflicts 12 | 10 dict begin 13 | %%EndProlog 14 | %%Page: 1 1 15 | % Translate for offset 16 | 14.173228346456694 14.173228346456694 translate 17 | % Translate to begin of first scanline 18 | 0 34.283156653392524 translate 19 | 34.283156653392524 -34.283156653392524 scale 20 | % Image geometry 21 | 60 60 8 22 | % Transformation matrix 23 | [ 60 0 0 60 0 0 ] 24 | % Strings to hold RGB-samples per scanline 25 | /rstr 60 string def 26 | /gstr 60 string def 27 | /bstr 60 string def 28 | {currentfile /ASCII85Decode filter /RunLengthDecode filter rstr readstring pop} 29 | {currentfile /ASCII85Decode filter /RunLengthDecode filter gstr readstring pop} 30 | {currentfile /ASCII85Decode filter /RunLengthDecode filter bstr readstring pop} 31 | true 3 32 | %%BeginData: 11305 ASCII Bytes 33 | colorimage 34 | a*7RPJ,~> 35 | a*7RPJ,~> 36 | a*7RPJ,~> 37 | !-d<""9%lTeaWS?!:TB,~> 38 | !-d<""9%lWg$o"C!:TB,~> 39 | !-d<""9%oYg@5+D!:TB,~> 40 | !-dH&#lEiJmI0Z@f(\_7!W^X:J,~> 41 | !-dH&#lErRo(2YQi:ldA!W^X:J,~> 42 | !-dH&#lEuToCr+Zj7r0E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6fs8a`da4J,~> 251 | rpRtV!:PF~> 252 | rpRtV!:PF~> 253 | rpRtV!:PF~> 254 | %%EndData 255 | showpage 256 | %%Trailer 257 | end 258 | %%EOF 259 | -------------------------------------------------------------------------------- /en/textedit-icon2.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: GIMP PostScript file plugin V 1.17 by Peter Kirchgessner 3 | %%Title: textedit-icon2.eps 4 | %%CreationDate: Sat Nov 17 17:40:52 2007 5 | %%DocumentData: Clean7Bit 6 | %%LanguageLevel: 2 7 | %%Pages: 1 8 | %%BoundingBox: 14 14 68 30 9 | %%EndComments 10 | %%BeginProlog 11 | % Use own dictionary to avoid conflicts 12 | 10 dict begin 13 | %%EndProlog 14 | %%Page: 1 1 15 | % Translate for offset 16 | 14.173228346456694 14.173228346456694 translate 17 | % Translate to begin of first scanline 18 | 0 14.856034549803427 translate 19 | 53.710278756981623 -14.856034549803427 scale 20 | % Image geometry 21 | 94 26 8 22 | % Transformation matrix 23 | [ 94 0 0 26 0 0 ] 24 | % Strings to hold RGB-samples per scanline 25 | /rstr 94 string def 26 | /gstr 94 string def 27 | /bstr 94 string def 28 | {currentfile /ASCII85Decode filter /RunLengthDecode filter rstr readstring pop} 29 | {currentfile /ASCII85Decode filter /RunLengthDecode filter gstr readstring pop} 30 | {currentfile /ASCII85Decode filter /RunLengthDecode filter bstr readstring pop} 31 | true 3 32 | %%BeginData: 4659 ASCII Bytes 33 | colorimage 34 | g&D0Qjn\o%s*t~> 35 | gA_ 36 | gA_ 37 | U]5i~> 38 | U]5i~> 39 | U]5i~> 40 | oD]!nr;?HhrjVoX~> 41 | o`+sjrVQZp\,Us~> 42 | o`+sjs82rqr;O2*J,~> 43 | p&> 44 | pAYHurV?'NiniVhrODlX~> 45 | pAYHurV?$Mj5/_hrODlX~> 46 | qu70*qtTdJi7QT3g>_DJmeaNoJ,~> 47 | r;Zfr%K-(rn*&cgiT07mi:?cTs*t~> 48 | r;Z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IDmcrr3l6Y<*@a/a_u+N;!;LTn(GgqhmRuk5Rp[$2tPN 118 | fBTj]!(ilG\GuS5]'fOj8N"!HrVqB~> 119 | qu79-q:Y35q>9p\p"uT-][b]jo(W.dp.2d`rr3l5XZ[@d0C8,*N;!;KTRb>fqhmY"jSqa]%K7%T 120 | fBK^]!)0&I[f?A5\aKFh9K9KKrVqB~> 121 | qYq-(cK"ThlM0npP;dZhc/8!emf*@dp@RtV!r)Efp\t9lo(E"`oD8CbJ,~> 122 | qYq-)g$AJ/oDJ:7VG2uaf]_r)mf*@dq=aF[!r;Wjp\t9lp%A=dpAFpgs*t~> 123 | qYq-(g?\Y8s8DTAVc/SjfB;`%mf*@dq"F=Z!r;Wjp\t9lp%A=dpA=jfs*t~> 124 | qYq')fZ_Ulm)-3:PrGi9qu+)*J,~> 125 | qYq**in2o?m``MbW(aqur;HW]s8W)is8W)krrE&krrE&qs*t~> 126 | qYq**in2`!ZC\23VG=esqu-N\s8W)is8W)krrE&krrE&qs*t~> 127 | q>UikhTj$[b1tmkO6c_Qs*t~> 128 | qYq$(oB+`PdadFAcD0n,rj_uY~> 129 | qYq$(o&nH2TY]IGcD'e*rj_uY~> 130 | q>Ufuo]tJplLsu 131 | q>Ug"p@%8/nG)hKir-=cJ,~> 132 | q>Ug!p?phflhL;EiVg4bJ,~> 133 | U]5i~> 134 | U]5i~> 135 | U]5i~> 136 | U]5i~> 137 | U]5i~> 138 | U]5i~> 139 | U]5i~> 140 | U]5i~> 141 | U]5i~> 142 | %%EndData 143 | showpage 144 | %%Trailer 145 | end 146 | %%EOF 147 | -------------------------------------------------------------------------------- /en/windows-edition.eps: -------------------------------------------------------------------------------- 1 | %!PS-Adobe-3.0 EPSF-3.0 2 | %%Creator: inkscape 0.45.1 3 | %%Pages: 1 4 | %%Orientation: Portrait 5 | %%BoundingBox: 63 321 461 405 6 | %%HiResBoundingBox: 63.143934 321.72031 460.97183 404.30317 7 | %%EndComments 8 | %%Page: 1 1 9 | 0 842 translate 10 | 0.8 -0.8 scale 11 | 0 0 0 setrgbcolor 12 | [] 0 setdash 13 | 1 setlinewidth 14 | 0 setlinejoin 15 | 0 setlinecap 16 | gsave [1 0 0 1 0 0] concat 17 | 1 0 0 setrgbcolor 18 | [] 0 setdash 19 | 11.458478 setlinewidth 20 | 1 setlinejoin 21 | 0 setlinecap 22 | newpath 23 | 114.67006 552.71246 moveto 24 | 540.47464 552.71246 lineto 25 | 557.10068 552.71246 570.48554 566.09733 570.48554 582.72337 curveto 26 | 570.48554 614.47165 lineto 27 | 570.48554 631.0977 557.10068 644.48256 540.47464 644.48256 curveto 28 | 114.67006 644.48256 lineto 29 | 98.044021 644.48256 84.659157 631.0977 84.659157 614.47165 curveto 30 | 84.659157 582.72337 lineto 31 | 84.659157 566.09733 98.044021 552.71246 114.67006 552.71246 curveto 32 | closepath 33 | stroke 34 | gsave 35 | 1 0 0 setrgbcolor 36 | newpath 37 | 113.51743 615.1886 moveto 38 | 117.58923 615.1886 lineto 39 | 127.67757 581.94568 lineto 40 | 137.94824 615.1886 lineto 41 | 142.08081 615.1886 lineto 42 | 151.74374 577.69156 lineto 43 | 155.81554 576.84074 lineto 44 | 155.81554 574.40981 lineto 45 | 143.2355 574.40981 lineto 46 | 143.2355 576.84074 lineto 47 | 147.3073 577.57002 lineto 48 | 147.97581 578.42084 lineto 49 | 140.62225 606.92345 lineto 50 | 130.65546 574.40981 lineto 51 | 126.40134 574.40981 lineto 52 | 116.61686 606.25494 lineto 53 | 108.77712 578.17775 lineto 54 | 109.26331 577.32692 lineto 55 | 113.09202 576.84074 lineto 56 | 113.09202 574.40981 lineto 57 | 99.478828 574.40981 lineto 58 | 99.478828 576.84074 lineto 59 | 103.30754 577.69156 lineto 60 | 113.51743 615.1886 lineto 61 | fill 62 | grestore 63 | gsave 64 | 1 0 0 setrgbcolor 65 | newpath 66 | 165.21924 572.1612 moveto 67 | 163.2745 572.1612 161.6944 573.68054 161.6944 575.68605 curveto 68 | 161.6944 577.63079 163.2745 579.15012 165.21924 579.15012 curveto 69 | 167.16398 579.15012 168.74408 577.63079 168.74408 575.68605 curveto 70 | 168.74408 573.74131 167.16398 572.1612 165.21924 572.1612 curveto 71 | 164.97615 585.65285 moveto 72 | 157.98723 587.84068 lineto 73 | 157.98723 589.72465 lineto 74 | 162.24135 589.72465 lineto 75 | 162.24135 611.72453 lineto 76 | 161.20821 612.6969 lineto 77 | 157.98723 613.00077 lineto 78 | 157.98723 615.1886 lineto 79 | 171.66119 615.1886 lineto 80 | 171.66119 613.00077 lineto 81 | 168.37944 612.6969 lineto 82 | 167.28553 611.72453 lineto 83 | 167.28553 585.65285 lineto 84 | 164.97615 585.65285 lineto 85 | fill 86 | grestore 87 | gsave 88 | 1 0 0 setrgbcolor 89 | newpath 90 | 174.65712 615.1886 moveto 91 | 187.96644 615.1886 lineto 92 | 187.96644 613.00077 lineto 93 | 185.04933 612.6969 lineto 94 | 184.01618 611.72453 lineto 95 | 184.01618 591.36552 lineto 96 | 186.62943 590.02851 188.87804 589.36001 190.82278 589.36001 curveto 97 | 195.31999 589.36001 196.96087 591.18321 196.96087 595.61964 curveto 98 | 196.96087 611.72453 lineto 99 | 195.92772 612.6969 lineto 100 | 193.01061 613.00077 lineto 101 | 193.01061 615.1886 lineto 102 | 206.31993 615.1886 lineto 103 | 206.31993 613.00077 lineto 104 | 203.03818 612.6969 lineto 105 | 202.00504 611.72453 lineto 106 | 202.00504 594.5865 lineto 107 | 202.00504 588.50919 199.08792 585.34898 193.80066 585.34898 curveto 108 | 191.18742 585.34898 188.08798 586.74676 184.01618 588.99537 curveto 109 | 184.01618 585.65285 lineto 110 | 181.7068 585.65285 lineto 111 | 174.65712 587.84068 lineto 112 | 174.65712 589.72465 lineto 113 | 178.97201 589.72465 lineto 114 | 178.97201 611.72453 lineto 115 | 177.93887 612.6969 lineto 116 | 174.65712 613.00077 lineto 117 | 174.65712 615.1886 lineto 118 | fill 119 | grestore 120 | gsave 121 | 1 0 0 setrgbcolor 122 | newpath 123 | 230.65103 574.53136 moveto 124 | 230.65103 585.95671 lineto 125 | 228.76707 585.5313 226.94387 585.28821 225.24222 585.28821 curveto 126 | 216.00471 585.28821 209.56275 591.79094 209.56275 601.51464 curveto 127 | 209.56275 610.02287 214.6677 615.73556 221.29197 615.73556 curveto 128 | 224.63449 615.73556 227.55161 614.52009 230.65103 612.02839 curveto 129 | 230.65103 615.1886 lineto 130 | 239.64546 615.1886 lineto 131 | 239.64546 613.00077 lineto 132 | 236.72835 612.6969 lineto 133 | 235.69521 611.72453 lineto 134 | 235.69521 570.45956 lineto 135 | 233.38583 570.45956 lineto 136 | 225.9715 572.64739 lineto 137 | 225.9715 574.53136 lineto 138 | 230.65103 574.53136 lineto 139 | 230.65103 609.77979 moveto 140 | 228.40243 611.17757 226.21459 611.90685 224.02676 611.90685 curveto 141 | 218.55718 611.90685 214.91079 607.59195 214.91079 600.4815 curveto 142 | 214.91079 592.88486 219.16491 587.96223 225.303 587.96223 curveto 143 | 226.76155 587.96223 228.58475 588.32686 230.65103 588.9346 curveto 144 | 230.65103 609.77979 lineto 145 | fill 146 | grestore 147 | gsave 148 | 1 0 0 setrgbcolor 149 | newpath 150 | 258.0265 585.34898 moveto 151 | 249.82213 585.34898 243.92713 591.48708 243.92713 600.54227 curveto 152 | 243.92713 609.53669 249.8829 615.73556 258.0265 615.73556 curveto 153 | 266.17009 615.73556 272.18664 609.53669 272.18664 600.54227 curveto 154 | 272.18664 591.54785 266.23087 585.34898 258.0265 585.34898 curveto 155 | 258.0265 587.96223 moveto 156 | 262.94912 587.96223 266.47397 592.70254 266.47397 600.54227 curveto 157 | 266.47397 608.44277 262.94912 613.12231 258.0265 613.12231 curveto 158 | 253.16465 613.12231 249.6398 608.382 249.6398 600.54227 curveto 159 | 249.6398 592.64177 253.10388 587.96223 258.0265 587.96223 curveto 160 | fill 161 | grestore 162 | gsave 163 | 1 0 0 setrgbcolor 164 | newpath 165 | 274.3175 585.95671 moveto 166 | 274.3175 588.20532 lineto 167 | 278.02466 588.56996 lineto 168 | 286.10749 615.1886 lineto 169 | 289.87543 615.1886 lineto 170 | 298.07981 592.15557 lineto 171 | 305.43336 615.1886 lineto 172 | 309.20129 615.1886 lineto 173 | 317.89185 588.6915 lineto 174 | 321.29515 588.20532 lineto 175 | 321.29515 585.95671 lineto 176 | 310.5383 585.95671 lineto 177 | 310.5383 588.20532 lineto 178 | 313.82005 588.44841 lineto 179 | 314.30624 589.42078 lineto 180 | 308.10738 609.17206 lineto 181 | 300.93614 585.95671 lineto 182 | 297.22898 585.95671 lineto 183 | 289.08538 609.17206 lineto 184 | 283.55502 589.42078 lineto 185 | 284.2843 588.44841 lineto 186 | 287.50528 588.20532 lineto 187 | 287.50528 585.95671 lineto 188 | 274.3175 585.95671 lineto 189 | fill 190 | grestore 191 | gsave 192 | 1 0 0 setrgbcolor 193 | newpath 194 | 342.23054 586.68599 moveto 195 | 340.16426 585.77439 337.7941 585.34898 335.12008 585.34898 curveto 196 | 328.19195 585.34898 324.36324 588.50919 324.36324 593.85722 curveto 197 | 324.36324 597.92902 327.03726 599.87377 332.20297 602.18314 curveto 198 | 336.214 604.00634 338.40183 605.10026 338.40183 608.26046 curveto 199 | 338.40183 611.11679 336.214 613.18308 332.68916 613.18308 curveto 200 | 330.92674 613.18308 329.22509 612.6969 327.52344 611.72453 curveto 201 | 326.79416 606.55881 lineto 202 | 323.87705 606.55881 lineto 203 | 323.87705 614.45932 lineto 204 | 326.00411 615.24937 328.67813 615.73556 331.77756 615.73556 curveto 205 | 338.94879 615.73556 343.14214 612.27148 343.14214 606.61958 curveto 206 | 343.14214 604.37098 342.29131 602.54778 340.83276 601.39309 curveto 207 | 338.82725 599.75222 336.51786 598.90139 334.39081 597.86825 curveto 208 | 330.98751 596.22738 329.22509 594.95114 329.22509 592.33789 curveto 209 | 329.22509 589.6031 331.04829 587.96223 334.26926 587.96223 curveto 210 | 335.72781 587.96223 337.18637 588.38764 338.76647 589.23846 curveto 211 | 339.25266 593.55336 lineto 212 | 342.23054 593.55336 lineto 213 | 342.23054 586.68599 lineto 214 | fill 215 | grestore 216 | gsave 217 | 1 0 0 setrgbcolor 218 | newpath 219 | fill 220 | grestore 221 | gsave 222 | 1 0 0 setrgbcolor 223 | newpath 224 | 364.51816 615.1886 moveto 225 | 395.81633 615.1886 lineto 226 | 395.81633 605.28257 lineto 227 | 392.65613 605.28257 lineto 228 | 391.62298 611.42066 lineto 229 | 390.77216 612.39303 lineto 230 | 374.48495 612.39303 lineto 231 | 374.48495 595.37655 lineto 232 | 384.45175 595.37655 lineto 233 | 385.30258 596.28815 lineto 234 | 385.91031 600.66381 lineto 235 | 388.76664 600.66381 lineto 236 | 388.76664 587.29372 lineto 237 | 385.91031 587.29372 lineto 238 | 385.30258 591.73016 lineto 239 | 384.45175 592.58098 lineto 240 | 374.48495 592.58098 lineto 241 | 374.48495 577.20538 lineto 242 | 388.52355 577.20538 lineto 243 | 389.37438 578.11697 lineto 244 | 390.2252 583.28269 lineto 245 | 393.6285 583.28269 lineto 246 | 393.6285 574.40981 lineto 247 | 364.51816 574.40981 lineto 248 | 364.51816 576.84074 lineto 249 | 367.98223 577.20538 lineto 250 | 369.01537 578.0562 lineto 251 | 369.01537 611.54221 lineto 252 | 367.98223 612.39303 lineto 253 | 364.51816 612.6969 lineto 254 | 364.51816 615.1886 lineto 255 | fill 256 | grestore 257 | gsave 258 | 1 0 0 setrgbcolor 259 | newpath 260 | 420.80454 574.53136 moveto 261 | 420.80454 585.95671 lineto 262 | 418.92057 585.5313 417.09737 585.28821 415.39573 585.28821 curveto 263 | 406.15822 585.28821 399.71625 591.79094 399.71625 601.51464 curveto 264 | 399.71625 610.02287 404.8212 615.73556 411.44547 615.73556 curveto 265 | 414.78799 615.73556 417.70511 614.52009 420.80454 612.02839 curveto 266 | 420.80454 615.1886 lineto 267 | 429.79896 615.1886 lineto 268 | 429.79896 613.00077 lineto 269 | 426.88185 612.6969 lineto 270 | 425.84871 611.72453 lineto 271 | 425.84871 570.45956 lineto 272 | 423.53933 570.45956 lineto 273 | 416.125 572.64739 lineto 274 | 416.125 574.53136 lineto 275 | 420.80454 574.53136 lineto 276 | 420.80454 609.77979 moveto 277 | 418.55593 611.17757 416.3681 611.90685 414.18026 611.90685 curveto 278 | 408.71069 611.90685 405.06429 607.59195 405.06429 600.4815 curveto 279 | 405.06429 592.88486 409.31842 587.96223 415.4565 587.96223 curveto 280 | 416.91505 587.96223 418.73825 588.32686 420.80454 588.9346 curveto 281 | 420.80454 609.77979 lineto 282 | fill 283 | grestore 284 | gsave 285 | 1 0 0 setrgbcolor 286 | newpath 287 | 441.19107 572.1612 moveto 288 | 439.24634 572.1612 437.66623 573.68054 437.66623 575.68605 curveto 289 | 437.66623 577.63079 439.24634 579.15012 441.19107 579.15012 curveto 290 | 443.13581 579.15012 444.71592 577.63079 444.71592 575.68605 curveto 291 | 444.71592 573.74131 443.13581 572.1612 441.19107 572.1612 curveto 292 | 440.94798 585.65285 moveto 293 | 433.95907 587.84068 lineto 294 | 433.95907 589.72465 lineto 295 | 438.21319 589.72465 lineto 296 | 438.21319 611.72453 lineto 297 | 437.18005 612.6969 lineto 298 | 433.95907 613.00077 lineto 299 | 433.95907 615.1886 lineto 300 | 447.63303 615.1886 lineto 301 | 447.63303 613.00077 lineto 302 | 444.35128 612.6969 lineto 303 | 443.25736 611.72453 lineto 304 | 443.25736 585.65285 lineto 305 | 440.94798 585.65285 lineto 306 | fill 307 | grestore 308 | gsave 309 | 1 0 0 setrgbcolor 310 | newpath 311 | 454.1538 589.6031 moveto 312 | 454.1538 609.23283 lineto 313 | 454.1538 613.54772 455.43004 615.37092 460.47421 615.37092 curveto 314 | 462.84436 615.37092 465.57916 614.94551 468.43549 614.03391 curveto 315 | 468.43549 611.7853 lineto 316 | 467.03771 612.08917 465.63993 612.27149 464.24214 612.27149 curveto 317 | 459.98803 612.27149 459.19797 610.26597 459.19797 605.64721 curveto 318 | 459.19797 589.6031 lineto 319 | 468.43549 589.6031 lineto 320 | 468.43549 586.74676 lineto 321 | 459.19797 586.74676 lineto 322 | 459.19797 580.30481 lineto 323 | 456.94937 580.30481 lineto 324 | 454.33612 585.95671 lineto 325 | 450.32509 587.71913 lineto 326 | 450.32509 589.6031 lineto 327 | 454.1538 589.6031 lineto 328 | fill 329 | grestore 330 | gsave 331 | 1 0 0 setrgbcolor 332 | newpath 333 | 478.46213 572.1612 moveto 334 | 476.51739 572.1612 474.93729 573.68054 474.93729 575.68605 curveto 335 | 474.93729 577.63079 476.51739 579.15012 478.46213 579.15012 curveto 336 | 480.40687 579.15012 481.98697 577.63079 481.98697 575.68605 curveto 337 | 481.98697 573.74131 480.40687 572.1612 478.46213 572.1612 curveto 338 | 478.21904 585.65285 moveto 339 | 471.23013 587.84068 lineto 340 | 471.23013 589.72465 lineto 341 | 475.48425 589.72465 lineto 342 | 475.48425 611.72453 lineto 343 | 474.4511 612.6969 lineto 344 | 471.23013 613.00077 lineto 345 | 471.23013 615.1886 lineto 346 | 484.90409 615.1886 lineto 347 | 484.90409 613.00077 lineto 348 | 481.62234 612.6969 lineto 349 | 480.52842 611.72453 lineto 350 | 480.52842 585.65285 lineto 351 | 478.21904 585.65285 lineto 352 | fill 353 | grestore 354 | gsave 355 | 1 0 0 setrgbcolor 356 | newpath 357 | 502.4248 585.34898 moveto 358 | 494.22043 585.34898 488.32543 591.48708 488.32543 600.54227 curveto 359 | 488.32543 609.53669 494.2812 615.73556 502.4248 615.73556 curveto 360 | 510.56839 615.73556 516.58494 609.53669 516.58494 600.54227 curveto 361 | 516.58494 591.54785 510.62917 585.34898 502.4248 585.34898 curveto 362 | 502.4248 587.96223 moveto 363 | 507.34742 587.96223 510.87227 592.70254 510.87227 600.54227 curveto 364 | 510.87227 608.44277 507.34742 613.12231 502.4248 613.12231 curveto 365 | 497.56295 613.12231 494.0381 608.382 494.0381 600.54227 curveto 366 | 494.0381 592.64177 497.50218 587.96223 502.4248 587.96223 curveto 367 | fill 368 | grestore 369 | gsave 370 | 1 0 0 setrgbcolor 371 | newpath 372 | 520.66054 615.1886 moveto 373 | 533.96986 615.1886 lineto 374 | 533.96986 613.00077 lineto 375 | 531.05275 612.6969 lineto 376 | 530.01961 611.72453 lineto 377 | 530.01961 591.36552 lineto 378 | 532.63285 590.02851 534.88146 589.36001 536.8262 589.36001 curveto 379 | 541.32341 589.36001 542.96429 591.18321 542.96429 595.61964 curveto 380 | 542.96429 611.72453 lineto 381 | 541.93115 612.6969 lineto 382 | 539.01404 613.00077 lineto 383 | 539.01404 615.1886 lineto 384 | 552.32336 615.1886 lineto 385 | 552.32336 613.00077 lineto 386 | 549.04161 612.6969 lineto 387 | 548.00846 611.72453 lineto 388 | 548.00846 594.5865 lineto 389 | 548.00846 588.50919 545.09135 585.34898 539.80409 585.34898 curveto 390 | 537.19084 585.34898 534.09141 586.74676 530.01961 588.99537 curveto 391 | 530.01961 585.65285 lineto 392 | 527.71023 585.65285 lineto 393 | 520.66054 587.84068 lineto 394 | 520.66054 589.72465 lineto 395 | 524.97544 589.72465 lineto 396 | 524.97544 611.72453 lineto 397 | 523.94229 612.6969 lineto 398 | 520.66054 613.00077 lineto 399 | 520.66054 615.1886 lineto 400 | fill 401 | grestore 402 | grestore 403 | showpage 404 | %%EOF 405 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | Это русский перевод книги "Snake Wrangling for Kids", позднее переработанной и выпущенной как "Python for kids". 2 | Это клон репозитория https://code.google.com/p/swfk/, там книгу писал автор, Jason R Briggs. 3 | 4 | В этом репозитории есть оригинальная книга без изменений в папке en, она как-то собирается при помощи latex и dvipdf. 5 | В папке ru есть перевод (незаконченный, начатый с линуксовой версии для Питона 3), он собирается командой 6 | ./build.sh 7 | которая вызывает xelatex и собирает все три версии книги. Можно собрать только нужную/нужные версии, так: 8 | ./build.sh macos 9 | 10 | Ну и свежие собранные версии есть там же, book-linux.pdf, book-windows.pdf и book-macos.pdf (собраны из тех же исходников, которые лежат в свежем коммите). 11 | 12 | Книга распространяется на условиях лицензии Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License, что значит, что её можно читать, изменять и невозбранно распространять, но только под той же лицензией, бесплатно и обязательно указывая понятным образом авторство разных частей (как минимум, «оригинальной» и изменённой последним автором). 13 | Подробнее тут почитайте: http://creativecommons.org/licenses/by-nc-sa/3.0/nz/deed.ru 14 | 15 | 16 | This is an unofficial clone of LaTeX source of "Snake Wrangling for Kids" 17 | The original repository was copied from here: https://code.google.com/p/swfk/, where it was maintained by the original book author, Jason R Briggs. 18 | 19 | This repository contains both the original English book 20 | and its Russian translation (with priority in translating to the Linux edition). 21 | 22 | This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 23 | To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 24 | 25 | To build, you'll need xelatex (unlike the original book which builds with latex and dvipdf). 26 | The easiest way to build the translated book is to go to the folder 'ru' and run: 27 | ./build.sh 28 | or, for just some versions: 29 | ./build.sh macos linux 30 | ./build.sh windows 31 | ./build.sh help 32 | If you input an incorrect target (e.g. 'help'), you'll get the list of all supported targets. 33 | 34 | -------------------------------------------------------------------------------- /ru/.gitignore: -------------------------------------------------------------------------------- 1 | comment.cut 2 | 06.py 3 | -------------------------------------------------------------------------------- /ru/03.house.eps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/ru/03.house.eps -------------------------------------------------------------------------------- /ru/03.house.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/ru/03.house.png -------------------------------------------------------------------------------- /ru/03.house.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | 3 | import turtle 4 | import sys 5 | t = turtle.Pen() 6 | t.forward (100) 7 | t.left(90) 8 | t.forward(100) 9 | t.left(90) 10 | t.forward(100) 11 | t.right(135) 12 | t.forward(71) 13 | t.right(90) 14 | t.forward(71) 15 | t.right(90) 16 | t.forward(141) 17 | t.right(135) 18 | t.forward(100) 19 | t.right(135) 20 | t.forward(141) 21 | 22 | sys.stdin.readline() 23 | -------------------------------------------------------------------------------- /ru/06.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | 5 | def yearly_savings(chores, paper, spending): 6 | print ('>>> yearly_savings (%s, %s, %s)' % (chores, paper, spending)) 7 | savings = 0 8 | for week in range(1, 10): 9 | savings = savings + chores + paper - spending 10 | print('К концу недели № %s накопится %s руб.' % (week, savings)) 11 | print ('(... и так далее ...)') 12 | 13 | def your_age(): 14 | print('>>> your_age()') 15 | print('Сколько тебе лет? Введи число и нажми Enter:') 16 | age = int(sys.stdin.readline()) 17 | if age >= 10 and age <= 13: 18 | print('Я знаю, тебе %s лет' % age) 19 | else: 20 | print('Столько люди не живут.') 21 | 22 | def interest (capital, years, percent): 23 | print ('>>> calculate_interest (%d, %d, %d)' % (capital, years, percent)) 24 | for i in range (0, years): 25 | print ('%s: %s' % (i, capital)) 26 | capital *= (1 + percent/100) 27 | print (capital) 28 | 29 | interest (1000, 1, 11) 30 | interest (1200, 5, 13) 31 | interest (1500, 10, 15) 32 | interest (50000, 5, 18) 33 | -------------------------------------------------------------------------------- /ru/07.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | f=open('06.py') 4 | g=open('/dev/null', 'w') 5 | nlines=0 6 | for line in f: 7 | nlines += 1 8 | 9 | f=open('06.py') 10 | for line in f: 11 | g.write(line) 12 | nlines -= 1 13 | print (nlines) 14 | 15 | -------------------------------------------------------------------------------- /ru/08.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import turtle 4 | import sys 5 | 6 | t = turtle.Pen() 7 | for x in range(1,9): 8 | t.forward(100) 9 | t.left(225) 10 | sys.stdin.readline() 11 | 12 | t.reset() 13 | for x in range(1,38): 14 | t.forward(100) 15 | t.left(175) 16 | sys.stdin.readline() 17 | 18 | t.reset() 19 | for x in range(1,20): 20 | t.forward(100) 21 | t.left(95) 22 | sys.stdin.readline() 23 | 24 | t.reset() 25 | for x in range(1,19): 26 | t.forward(100) 27 | if x % 2 == 0: 28 | t.left(175) 29 | else: 30 | t.left(225) 31 | sys.stdin.readline() 32 | -------------------------------------------------------------------------------- /ru/book-linux.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/ru/book-linux.pdf -------------------------------------------------------------------------------- /ru/book-macos.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/ru/book-macos.pdf -------------------------------------------------------------------------------- /ru/book-windows.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/ru/book-windows.pdf -------------------------------------------------------------------------------- /ru/book.tex: -------------------------------------------------------------------------------- 1 | % !TeX encoding = UTF-8 2 | % Use XeLaTeX to compile it 3 | % 4 | % Эта работа распространяется на условиях лицензии Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 5 | % Краткое описание лицензии есть тут: http://creativecommons.org/licenses/by-nc-sa/3.0/nz/deed.ru 6 | % Полное — там же. 7 | % Эту книгу можно невозбранно распространять и изменять, но только соблюдая следующие условия: 8 | % сохраняя лицензию и не вводя дополнительных ограничений, бесплатно 9 | % и указывая авторство как оригинальной части, так и изменённой. 10 | % Автор оригинального английского текста — Jason R Briggs http://jasonrbriggs.com/ 11 | % Автор перевода — Егор Кочетов 12 | % 13 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 14 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 15 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 16 | % 17 | 18 | \documentclass[a4paper,12pt]{book} 19 | 20 | \RequirePackage{polyglossia} 21 | \setdefaultlanguage{russian} 22 | % \setotherlanguage{english} 23 | 24 | \RequirePackage{microtype} 25 | \setmainfont[Ligatures=TeX]{CMU Serif} 26 | \setsansfont[Ligatures=TeX]{CMU Sans Serif} 27 | \setmonofont[Ligatures=TeX]{CMU Typewriter Text} 28 | 29 | % \setmonofont{DejaVuSansMono} 30 | % \setmonofont{LiberationMono-Regular} 12 | % 13 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 14 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 15 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 16 | % 17 | 18 | \chapter{Черепахи и другие медленные создания}\index{черепашка}\label{ch:turtles} 19 | 20 | Есть нечто общее между черепахами из реального мира и черепахой в Питоне. В реальном мире черепаха — это (иногда) зелёная рептилия, которая движется очень медленно и носит на себе свой дом. В мире Питона всё почти так же: черепаха — это маленькая чёрная стрелочка, которая очень медленно ползает по экрану. Правда, с домиком у этой стрелочки не сложилось. 21 | 22 | Вообще, черепашка в Питоне оставляет за собой след, так что она похожа больше на улитку, чем на черепаху. Но «черепаха» звучит более гордо, так что модуль в Питоне называется именно так. Можно представлять себе черепаху, зажавшую в зубах маркер и рисующую, пока ползёт. 23 | 24 | Давным-давно, в тёмные старые времена люди придумали язык программирования Лого (Logo). Это был язык для управления роботом-черепашкой Ирвингом. Со временем черепашка превратилась из робота, ползающего по полу, в маленькую стрелочку, перемещающуюся по экрану. 25 | 26 | \btw{Что, кстати, показывает нам, что с развитием технологии не всегда всё улучшается. Маленькая робот-черепашка на полу была бы куда как забавнее.} 27 | 28 | В Питоне есть модуль\footnote{Про модули подробно поговорим мы чуть позже, а пока просто стоит иметь в виду, что модуль — это что-то, что можно использовать в своей программе, набор разных функций.} \code{turtle} (черепаха), и он в целом похож на язык Лого. Только Лого ничего, кроме черепашки, и не умеет, а Питон умеет ещё много всего другого. Модуль \code{turtle} полезен, чтобы понять, как компьютер рисует изображение на экране. 29 | 30 | Ладно, давай теперь просто посмотрим, как же этот модуль работает. Во-первых, его надо «импортировать», то есть сказать Питону, что он нам нужен: 31 | 32 | \begin{listing} 33 | \begin{verbatim} 34 | >>> import turtle 35 | \end{verbatim} 36 | \end{listing} 37 | 38 | Потом нам надо создать «холст» для рисования — смысл тот же, что и в реальном холсте, которым пользуются художники. Холст будет нужен, чтобы на нём рисовать. Мы создадим пустой: 39 | 40 | \begin{listing} 41 | \begin{verbatim} 42 | >>> t = turtle.Pen() 43 | \end{verbatim} 44 | \end{listing} 45 | 46 | Тут мы вызываем функцию \code{Pen}\index{черепашка!Pen} модуля \code{turtle}, и она автоматически создаёт холст (\emph{canvas} по-английски). Вообще, функция — это что-то вроде маленькой программы, то есть кусочек кода, который можно использовать много раз (подробно функции мы обсудим потом). В данном случае функция \code{Pen} \emph{возвращает} нам черепашку, то есть результат этой функции — черепашка, к которой мы приклеиваем переменную \code{t}. Результатом этого кода должна быть картинка наподобие \ref{fig10}. 47 | 48 | \begin{figure} 49 | \begin{center} 50 | \includegraphics[width=72mm]{../en/figure10.eps} 51 | \end{center} 52 | \caption{Стрелочка, изображающая черепаху}\label{fig10} 53 | \end{figure} 54 | 55 | \btw{Да, эта маленькая стрелочке посреди экрана — действительно черепаха. И да, на черепаху она внешне не похожа примерно ничем.} 56 | 57 | Этой черепахе можно отправлять инструкции, используя функции созданного объекта \code{t}. Вот, например, можно попросить черепаху продвинуться вперёд, туда, куда показывает стрелочка. Для этого есть функция \code{forward}, в скобках которой надо указать, на сколько точек на экране продвинуться. Например, чтобы подвинуть черепаху вперёд на 50 точек (и нарисовать линию длиной 50 точек), нужно выполнить такую команду: 58 | 59 | \begin{listing} 60 | \begin{verbatim} 61 | >>> t.forward(50) 62 | \end{verbatim} 63 | \end{listing} 64 | 65 | И в результате должно получиться как-то так:~\ref{fig11}. 66 | 67 | \begin{figure} 68 | \begin{center} 69 | \includegraphics[width=72mm]{../en/figure11.eps} 70 | \end{center} 71 | \caption{Черепашка нарисовала линию.}\label{fig11} 72 | \end{figure} 73 | 74 | С точки зрения черепахи, она прошла вперёд 50 шагов. А мы бы сказали, что она прошла 50 точек по экрану. 75 | 76 | \btw{И что это за точки такие?} 77 | 78 | Всё на экране компьютера состоит из отдельных маленьких точек, каждая из которых окрашена в свой цвет. Обычно их называют пикселями, чтобы не путать ни с какими другими точками, и так я и буду дальше делать. Все программы на компьютере, все игры заставляют точки на экране окрашиваться в разные нужные цвета. Эти отдельные точки можно увидеть, вооружившись лупой. Если сильно увеличить линию, нарисованную черепахой, то можно увидеть, что это много квадратных точек, оказавшихся рядом, как на картинке \ref{fig12}. 79 | 80 | \begin{figure} 81 | \begin{center} 82 | \includegraphics[width=72mm]{../en/figure12.eps} 83 | \end{center} 84 | \caption{Сильно увеличенные линия и стрелочка.}\label{fig12} 85 | \end{figure} 86 | 87 | В следующих главах мы ещё вспомним про пиксели, они нам пригодятся. 88 | 89 | Вернёмся к черепашке. Её ещё можно попросить повернуть направо\index{черепашка!поворот направо} и налево\index{черепашка!поворот налево}. 90 | 91 | \begin{listing} 92 | \begin{verbatim} 93 | >>> t.left(90) 94 | \end{verbatim} 95 | \end{listing} 96 | 97 | Эта команда говорит черепашке повернуть налево на 90 градусов (то есть против часовой стрелки). Если ты ещё не знаешь про градусы\index{градусы} и как ими меряют углы, то это можно представить себе вот как. На рисунке \ref{fig13} есть циферблат от часов. 98 | 99 | \begin{figure} 100 | \begin{center} 101 | \includegraphics[width=52mm]{../en/figure13.eps} 102 | \end{center} 103 | \caption{Циферблат с отметками часов}\label{fig13} 104 | \end{figure} 105 | 106 | На циферблате по кругу написаны числа от 1 до 12 (или до 60, если там написаны минуты). Так вот градусы пишутся так же по кругу, только всё умножается на 30. Вместо цифры 3 — 90° (90 градусов), вместо шести — 180°, как на рисунке \ref{fig14}. А черепашка как будто стоит в центре циферблата и смотрит в сторону нуля, наверх. 107 | 108 | \begin{figure} 109 | \begin{center} 110 | \includegraphics[width=52mm]{../en/figure14.eps} 111 | \end{center} 112 | \caption{Градусы.}\label{fig14} 113 | \end{figure} 114 | 115 | И что происходит, когда мы отдаём команду \code{left(90)}? 116 | 117 | Если встать, поднять руку ровно в сторону и показать туда, то чтобы повернуться лицом в ту сторону, в которую ты показываешь, нужно повернуться как раз на 90 градусов. Если показывать правой рукой, то на 90° вправо, левой рукой — на 90° влево. Так же и черепашка в питоне поворачивается туда, где её правый бок или левый. При этом голова черепашки остаётся на месте (рисует она как раз маркером, зажатым в зубах), так что функция \code{t.left(90)} приводит к тому, что есть на рисунке \ref{fig15}. Черепашка ползла вправо и повернула вверх. 118 | 119 | \begin{figure} 120 | \begin{center} 121 | \includegraphics[width=72mm]{../en/figure15.eps} 122 | \end{center} 123 | \caption{Черепашка, повернувшая налево.}\label{fig15} 124 | \end{figure} 125 | 126 | Давай теперь посмотрим, как все эти команды работают вместе: 127 | 128 | \begin{listing} 129 | \begin{verbatim} 130 | >>> t.forward(50) 131 | >>> t.left(90) 132 | >>> t.forward(50) 133 | >>> t.left(90) 134 | >>> t.forward(50) 135 | >>> t.left(90) 136 | \end{verbatim} 137 | \end{listing} 138 | 139 | На экране черепашка нарисовала квадрат и остановилась, глядя в ту же сторону, что и в начале пути, как на рисунке \ref{fig16}. 140 | 141 | \begin{figure} 142 | \begin{center} 143 | \includegraphics[width=72mm]{../en/figure16.eps} 144 | \end{center} 145 | \caption{Квадрат нарисовался.}\label{fig16} 146 | \end{figure} 147 | 148 | Можно взять и очистить весь холст, воспользовавшись функцией \code{clear}\index{черепашка!очистить} (что как раз и переводится как «очистить»): 149 | 150 | \begin{listing} 151 | \begin{verbatim} 152 | >>> t.clear() 153 | \end{verbatim} 154 | \end{listing} 155 | 156 | Есть и другие полезные функции, применимые к черепашке. Например, \code{reset}\index{черепашка!reset}: тоже очищает экран и ещё перемещает черепашку в начальное положение. Ещё есть функция \code{backward}, которая говорит черепашке двигаться назад (при этом направление её взгляда не меняется, она просто пятится). Функция \code{right} говорит черепашке повернуть направо; функция \code{up}\index{черепашка!прекратить рисовать} говорит ей оторвать маркер от холста, то есть перестать рисовать при движении: не всё можно нарисовать, если рисовать при каждом движении, иногда нужно просто переместиться. Есть и функция \code{down}\index{черепашка!начать рисовать}, которая говорит ей обратно опустить маркер на холст и снова рисовать, пока она перемещается. Все эти функции вызываются таким же образом, как в примерах выше: 157 | 158 | \begin{listing} 159 | \begin{verbatim} 160 | >>> t.reset() 161 | >>> t.backward(100) 162 | >>> t.right(90) 163 | >>> t.up() 164 | >>> t.down() 165 | \end{verbatim} 166 | \end{listing} 167 | 168 | В следующих главах мы ещё воспользуемся услугами черепашки. 169 | 170 | \section{Как ещё развлечься} 171 | 172 | \btw{В этой главе мы познакомились с маленькой черепашкой, которая нарисовала нам немного линий, поворачиваясь направо и налево. Ещё мы обсудили градусы, которые здорово похожи на числа на циферблате часов.} 173 | 174 | \subsection*{Упражнение 1} 175 | Создай холст, используя функцию \code{Pen}, и нарисуй там прямоугольник. 176 | 177 | \subsection*{Упражнение 2} 178 | Создай холст, используя функцию \code{Pen}, и нарисуй там треугольник. 179 | 180 | \subsection*{Упражнение 3*} 181 | Создай холст, используя функцию \code{Pen}, и нарисуй там домик, как на рисунке \ref{fighouse}, не отрывая маркер от холста (не пользуясь функцией \code{up}). Это упражнение сложнее предыдущих и может не получиться без посторонней помощи, ничего страшного\footnote{Чтобы всё получилось, нужно иметь в виду, что может понадобиться повернуть на 45 или 135 градусов и что если стороны домика длиной 100 точек, то косые линии будут длиной примерно 71 и 141 точка.}. 182 | 183 | \begin{figure} 184 | \begin{center} 185 | \includegraphics[width=72mm]{03.house.eps} 186 | \end{center} 187 | \caption{Домик, который нарисовали, не отрывая карандаш от бумаги.}\label{fighouse} 188 | \end{figure} 189 | 190 | \newpage 191 | -------------------------------------------------------------------------------- /ru/chapter4.tex: -------------------------------------------------------------------------------- 1 | % !TeX encoding = UTF-8 2 | % Use XeLaTeX to compile it 3 | % 4 | % Эта работа распространяется на условиях лицензии Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 5 | % Краткое описание лицензии есть тут: http://creativecommons.org/licenses/by-nc-sa/3.0/nz/deed.ru 6 | % Полное — там же. 7 | % Эту книгу можно невозбранно распространять и изменять, но только соблюдая следующие условия: 8 | % сохраняя лицензию и не вводя дополнительных ограничений, бесплатно 9 | % и указывая авторство как оригинальной части, так и изменённой. 10 | % Автор оригинального английского текста — Jason R Briggs http://jasonrbriggs.com/ 11 | % Автор перевода — Егор Кочетов 12 | % 13 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 14 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 15 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 16 | % 17 | 18 | \chapter{Как задать вопрос}\label{ch:howtoaskaquestion} 19 | 20 | С точки зрения программистов, вопрос задаётся тогда, когда в зависимости от ответа нужно выполнить одни команды или другие. Во многих языках программирования такой вопрос записывается с использованием слова \code{if}\index{if}, что на русский переводится как «если»\footnote{В некоторых языках прямо по-русски и пишут «если», но всё же обычно так не принято делать. В Питоне надо писать \code{if}.}. Такое выражение ещё называется \textbf{условным оператором}. 21 | 22 | \begin{quotation} 23 | Сколько тебе лет? Если тебе больше двадцати, ты супер стар! 24 | \end{quotation} 25 | 26 | Утверждение выше на Питоне может быть записано вот так: 27 | 28 | \begin{listing} 29 | \begin{verbatim} 30 | if возраст > 20: 31 | print('ты супер стар!') 32 | \end{verbatim} 33 | \end{listing} 34 | 35 | Условный оператор состоит из слова \code{if}, после которого записывается условие, завершаемое двоеточием (\code{:}). Все следующие строки, которые выполняются в зависимости от этого условия, должны начинаться с одинакового количества пробелов. Большинство людей использует тут 4 пробела, потому что так уже легко видеть \textit{блок кода}, и при этом он не слишком далеко уезжает направо. Для вставки такого отступа в начало строки обычно используют клавишу \texttt{Tab}, она на клавиатуре слева (←) под цифрами, слева от буквы Й. 36 | 37 | Если ответ на вопрос, который написан после \code{if}, — да, или \code{True}, как это записывается в Питоне, то блок кода, начинающийся с отступов, выполняется. 38 | 39 | Условие, которое надо писать после \code{if}, — это выражение, на которое можно ответить «да» (\code{True}, «истина») или «нет» (\code{False}, «ложь»). Чтобы записывать условия, есть специальные значки, вот они: 40 | 41 | \begin{center} 42 | \begin{tabular}{|c|c|} 43 | \hline 44 | $==$ & равно \\ 45 | \hline 46 | $!=$ & не равно \\ 47 | \hline 48 | $>$ & больше чем \\ 49 | \hline 50 | $<$ & меньше чем \\ 51 | \hline 52 | $>=$ & больше чем или равно \\ 53 | \hline 54 | $<=$ & меньше чем или равно \\ 55 | \hline 56 | \end{tabular} 57 | \end{center} 58 | 59 | Например, если тебе 10 лет, то условие \code{твой\_возраст == 10} истинно (равно \code{True}). Если же тебе не 10 лет, то оно ложно (равно \code{False}). Тут есть хитрость: чтобы сравнить два числа, надо написать два знака равенства подряд. Если написать только один, будет ошибка. А один знак нужно писать, чтобы в переменную занести какое-нибудь значение, то есть никак не после \code{if}. 60 | 61 | Теперь допустим, что тебе больше 10 лет и в переменной \code{age} хранится твой возраст. Тогда вот такое условие… 62 | 63 | \begin{listing} 64 | \begin{verbatim} 65 | age > 10 66 | \end{verbatim} 67 | \end{listing} 68 | 69 | …будет равно \code{True}. А если тебе меньше 10 лет, то это условие будет равно \code{False}. И если тебе 10 лет, условие тоже будет ложно, зато будет истинно условие \code{age>=10}. 70 | 71 | Давай попробуем теперь ввести примеры в консоль: 72 | 73 | \begin{listing} 74 | \begin{verbatim} 75 | >>> age = 10 76 | >>> if age > 10: 77 | ... print('я тут!') 78 | \end{verbatim} 79 | \end{listing} 80 | 81 | Если ввести это в консоль, что произойдёт?.. 82 | 83 | Да ничего. 84 | 85 | Переменная \code{age} не больше 10, так что \code{print} не выполнится. А как насчёт такого: 86 | 87 | \begin{listing} 88 | \begin{verbatim} 89 | >>> age = 10 90 | >>> if age >= 10: 91 | ... print('тут я!') 92 | \end{verbatim} 93 | \end{listing} 94 | 95 | Вот если этот пример запустить, то Питон выведет сообщение в консоль. И следующий пример тоже сработает: 96 | 97 | \begin{listing} 98 | \begin{verbatim} 99 | >>> age = 10 100 | >>> if age == 10: 101 | ... print('вот я где!') 102 | вот я где! 103 | \end{verbatim} 104 | \end{listing} 105 | 106 | \section{Сделай вот это… ИЛИ ВОТ ЭТО!} 107 | 108 | Можно расширить условный оператор и сказать Питону, что делать, когда условие ложно. Можно, например, напечатать в консоль «Привет», если тебе 12 лет или «Пока» в ином случае. Для этого пригодится слово \code{else} (в переводе — «иначе»)\index{else}. 109 | 110 | \begin{listing} 111 | \begin{verbatim} 112 | >>> age = 12 113 | >>> if age == 12: 114 | ... print('Привет!') 115 | ... else: 116 | ... print('Пока.') 117 | Привет! 118 | \end{verbatim} 119 | \end{listing} 120 | 121 | Если ты напечатаешь в консоль этот пример, то увидишь в ответ «Привет!». Стоит изменить значение переменной \code{age} на что-нибудь другое, как сообщение от Питона поменяется: 122 | 123 | \begin{listing} 124 | \begin{verbatim} 125 | >>> age = 8 126 | >>> if age == 12: 127 | ... print('Привет!') 128 | ... else: 129 | ... print('Пока.') 130 | Пока. 131 | \end{verbatim} 132 | \end{listing} 133 | 134 | \section{Сделай вот это… или ещё вот это… ИЛИ ВОТ ЭТО!} 135 | 136 | Можно ещё дальше расширить условный оператор, используя слово \code{elif} (сокращение от «else if»). Например, можно вот так печатать, сколько тебе лет (да, не слишком полезно, но позволяет ухватить суть этого условного оператора): 137 | 138 | \begin{listing} 139 | \begin{verbatim} 140 | 1. >>> age = 12 141 | 2. >>> if age == 10: 142 | 3. ... print('похоже, тебе 10 лет') 143 | 4. ... elif age == 11: 144 | 5. ... print('я знаю, тебе 11 лет') 145 | 6. ... elif age == 12: 146 | 7. ... print('ух ты, а тебе 12 лет') 147 | 8. ... elif age == 13: 148 | 9. ... print('тебе целых 13 лет!') 149 | 10. ... else: 150 | 11. ... print('Столько люди не живут.') 151 | 12. ... 152 | 13. ух ты, а тебе 12 лет 153 | \end{verbatim} 154 | \end{listing} 155 | 156 | В примере кода выше строка 2 проверяет, равно ли значение возраста 10. Если нет, то сразу после этого выполняется строчка 4, которая проверяет, равно ли значение возраста 11. Если нет — то проверяется условие в строке 6. Оно оказывается истинным, поэтому выполняется строка 7 и больше никаких проверок не производится. 157 | 158 | \section{Комбинируем условия}\index{условия!комбинации} 159 | Можно проверять внутри одного условия сразу несколько выражений. Для этого используются английские слова «и»: \code{and} и «или»: \code{or}. Так например, пример выше можно было бы записать следующим образом, объединив проверки в одно большое условие: 160 | 161 | \begin{listing} 162 | \begin{verbatim} 163 | 1. >>> if age == 10 or age == 11 or age == 12 or age == 13: 164 | 2. ... print('Я знаю, тебе %s лет' % age) 165 | 3. ... else: 166 | 4. ... print('Столько люди не живут.') 167 | \end{verbatim} 168 | \end{listing} 169 | 170 | Если любое из условий в строке 1 истинно, то все следующие и не проверяются и выполняется блок кода, следующий за \code{if}, то есть строка 2 в этом примере. Если же все условия ложны, то выполнится блок кода под \code{else}, то есть строчка 4. Этот пример можно ещё сократить, воспользовавшись операциями сравнения $<=$ и $>=$: 171 | 172 | \begin{listing} 173 | \begin{verbatim} 174 | 1. >>> if age >= 10 and age <= 13: 175 | 2. ... print('Тебе %s лет' % age) 176 | 3. ... else: 177 | 4. ... print('А сколько же?') 178 | \end{verbatim} 179 | \end{listing} 180 | 181 | Тут если твой возраст не меньше 10 лет и не больше 13, то Питон напечатает, сколько тебе лет, а иначе — удивится. 182 | 183 | \section{Пустота}\index{None} 184 | 185 | Есть ещё специальное значение, которое можно присвоить любой переменной, и о котором мы раньше не говорили: \textbf{ничего}. 186 | 187 | Точно так же, как переменной можно присвоить числа, строки и списки, переменной можно присвоить и «ничего». В Питоне это записывается словом \code{None} и значит, что в переменной ничего нет (в других языках используют слова типа \code{nil}, \code{null}, \code{nullptr}). При этом значение этой переменной можно напечатать, как и значение любой другой, и это не вызовет ошибки, как было бы, если бы переменная вообще не была объявлена. 188 | 189 | \begin{listing} 190 | \begin{verbatim} 191 | >>> myval = None 192 | >>> print(myval) 193 | None 194 | \end{verbatim} 195 | \end{listing} 196 | 197 | Присвоить переменной \code{None} может быть нужно, чтобы указать, что переменная чему-то будет равна потом, но сейчас её значение неизвестно\footnote{Если же хочется вообще удалить переменную, то надо не присвоить ей \code{None}, а написать вот так (для переменной \code{myval}): \code{del myval}.}. 198 | 199 | Вот пример: допустим, мы хотим сходить в кино втроём, и для этого нам надо скинуться деньгами, кому сколько не жалко. Когда все решат, сколько им не жалко, и положат сумму, например, в конверт, можно на эти деньги выбрать фильм и купить билеты (а чтобы показать все фильмы из ближайших кинотеатров, на которые хватит этих денег, вполне можно написать программу на Питоне). Так вот, для этого мы заведём три переменных для каждого из зрителей и запишем в них \code{None}, что будет значить, что человек ещё вообще не сдавал деньги (если бы мы записали туда 0, это бы значило, что человек не хочет и не будет сдавать денег): 200 | 201 | \begin{listing} 202 | \begin{verbatim} 203 | >>> зритель1 = None 204 | >>> зритель2 = None 205 | >>> зритель3 = None 206 | \end{verbatim} 207 | \end{listing} 208 | 209 | Теперь можно проверить, все ли сдали деньги, пользуясь \code{if}'ом: 210 | 211 | \begin{listing} 212 | \begin{verbatim} 213 | >>> if зритель1 is None or зритель2 is None or зритель3 is None: 214 | ... print('Надо подождать ещё, не все сдали деньги') 215 | ... else: 216 | ... print('Мы собрали %s руб.' % (зритель1 + зритель2 + зритель3)) 217 | \end{verbatim} 218 | \end{listing} 219 | 220 | \code{if} проверяет, записано ли в какую-то переменную значение \code{None} и, если это так, сообщает об этом. Если же в каждую переменную записано, кто сколько сдал денег, то Питон напечатает нам общую собранную сумму. 221 | 222 | Вот что будет, если только два человека решились: 223 | 224 | \begin{listing} 225 | \begin{verbatim} 226 | >>> зритель1 = 100 227 | >>> зритель2 = None 228 | >>> зритель3 = 300 229 | >>> if зритель1 is None or зритель2 is None or зритель3 is None: 230 | ... print('Надо подождать ещё, не все сдали деньги') 231 | ... else: 232 | ... print('Мы собрали %s руб.' % (зритель1 + зритель2 + зритель3)) 233 | Надо подождать ещё, не все сдали деньги 234 | \end{verbatim} 235 | \end{listing} 236 | 237 | А вот, если все трое: 238 | 239 | \begin{listing} 240 | \begin{verbatim} 241 | >>> зритель1 = 100 242 | >>> зритель2 = 500 243 | >>> зритель3 = 300 244 | >>> if зритель1 is None or зритель2 is None or зритель3 is None: 245 | ... print('Надо подождать ещё, не все сдали деньги') 246 | ... else: 247 | ... print('Мы собрали %s руб.' % (зритель1 + зритель2 + зритель3)) 248 | Мы собрали 900 руб. 249 | \end{verbatim} 250 | \end{listing} 251 | 252 | \section{В чём разница…?}\label{whatsthedifference}\index{равенство} 253 | 254 | Какая разница между \code{10} и \code{'10'}? 255 | 256 | Так вообще, кажется, что, кроме пары кавычек, её и нет. Хотя вот в предыдущих главах ты узнал, что \code{10} — это число, а \code{'10'} — строка. И это различие гораздо существеннее, чем можно подумать. 257 | 258 | Недавно мы проверяли, чему равен возраст, вот так: 259 | 260 | \begin{listing} 261 | \begin{verbatim} 262 | >>> if age == 10: 263 | ... print('помни: тебе 10 лет') 264 | \end{verbatim} 265 | \end{listing} 266 | 267 | И если в переменную \code{age} записать значение 10, то всё, что надо, на экране напечатается: 268 | 269 | \begin{listing} 270 | \begin{verbatim} 271 | >>> age = 10 272 | >>> if age == 10: 273 | ... print('помни: тебе 10 лет') 274 | ... 275 | помни: тебе 10 лет 276 | \end{verbatim} 277 | \end{listing} 278 | 279 | Но если в ту же переменную записать \code{'10'} (с кавычками), то ничего печататься не будет: 280 | 281 | \begin{listing} 282 | \begin{verbatim} 283 | >>> age = '10' 284 | >>> if age == 10: 285 | ... print('помни: тебе 10 лет') 286 | ... 287 | \end{verbatim} 288 | \end{listing} 289 | 290 | Как же так? Почему теперь ничего не работает? Ну потому что строка — это не число, хотя и выглядят они одинаково: 291 | 292 | \begin{listing} 293 | \begin{verbatim} 294 | >>> age1 = 10 295 | >>> age2 = '10' 296 | >>> print(age1) 297 | 10 298 | >>> print(age2) 299 | 10 300 | \end{verbatim} 301 | \end{listing} 302 | 303 | Вот, видишь! Выглядят совсем одинаково, если напечатать. Но число никогда не будет равно строке. 304 | 305 | Это вроде как странно, но смысл какой-то такой, что если сравнивать 10 книг и 10 кирпичей, они никогда не будут равны — они просто разные. То есть можно сравнить 10 штук книг и 10 штук кирпичей — количество (число) одинаковое, но сказать, что 10 кирпичей — это одно и то же («равно»), что и 10 книг, вряд ли получится. Вот так и тут. 306 | 307 | Но это не страшно, Питон умеет прочитать строку и понять, какое число там записано, и наоборот, записать цифрами число в строку. Вот так можно превратить строку \code{'10'} в число \code{10}: 308 | 309 | \begin{listing} 310 | \begin{verbatim} 311 | >>> age = '10' 312 | >>> converted_age = int(age) 313 | \end{verbatim} 314 | \end{listing} 315 | 316 | Теперь переменная \code{converted\_age} хранит число 10 (не строку). Функция \code{int}, которая используется для такого преобразования, названа как сокращение от английского слова «integer», что значит «целое число», число без дробной части, без запятой. 317 | 318 | Чтобы обратно перевести число в строку, есть функция \code{str} (сокращение от «string», «строка»): 319 | 320 | \begin{listing} 321 | \begin{verbatim} 322 | >>> age = 10 323 | >>> converted_age = str(age) 324 | \end{verbatim} 325 | \end{listing} 326 | 327 | Теперь в переменной \code{converted\_age} лежит строка \code{'10'}. Самое время вернуться к тому сравнению, которое у нас не работало: 328 | 329 | \begin{listing} 330 | \begin{verbatim} 331 | >>> age = '10' 332 | >>> if age == 10: 333 | ... print('Тебе %s лет' % age) 334 | ... 335 | \end{verbatim} 336 | \end{listing} 337 | 338 | Если мы преобразуем переменную перед проверкой, тогда мы получим другой результат: 339 | 340 | \begin{listing} 341 | \begin{verbatim} 342 | >>> age = '10' 343 | >>> converted_age = int(age) 344 | >>> if converted_age == 10: 345 | ... print('Тебе %s лет' % age) 346 | ... 347 | Тебе 10 лет 348 | \end{verbatim} 349 | \end{listing} 350 | 351 | Или даже прямо так, короче и без дополнительной переменной: 352 | 353 | \begin{listing} 354 | \begin{verbatim} 355 | >>> age = '10' 356 | >>> if int(age) == 10: 357 | ... print('Тебе %s лет' % age) 358 | ... 359 | Тебе 10 лет 360 | \end{verbatim} 361 | \end{listing} 362 | -------------------------------------------------------------------------------- /ru/chapter7.tex: -------------------------------------------------------------------------------- 1 | % !TeX encoding = UTF-8 2 | % Use XeLaTeX to compile it 3 | % 4 | % Эта работа распространяется на условиях лицензии Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 5 | % Краткое описание лицензии есть тут: http://creativecommons.org/licenses/by-nc-sa/3.0/nz/deed.ru 6 | % Полное — там же. 7 | % Эту книгу можно невозбранно распространять и изменять, но только соблюдая следующие условия: 8 | % сохраняя лицензию и не вводя дополнительных ограничений, бесплатно 9 | % и указывая авторство как оригинальной части, так и изменённой. 10 | % Автор оригинального английского текста — Jason R Briggs http://jasonrbriggs.com/ 11 | % Автор перевода — Егор Кочетов 12 | % 13 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 14 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 15 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 16 | % 17 | 18 | \chapter{Коротенькая глава про файлы}\label{ch:ashortchapteraboutfiles}\index{функции!file} 19 | 20 | Может статься, ты уже слышал, что такое файлы (тем более, что в прошлой главе мы их использовали). Но я на всякий случай расскажу. 21 | 22 | Наверное, тебе доводилось сталкиваться с такими плоскими полиэтиленовыми папками для бумаг на кольцах — они обычно называются файлами. В них можно вкладывать какие-то записи на русском, английском, удмуртском языках (например) и ещё приклеивать на них наклейку с названием. И потом их можно складывать в большие картонные папки, чтобы все эти файлики лежали рядом. 23 | 24 | В компьютере всё примерно так же, только файлов можно создавать из ничего сколько угодно (ну… почти, пока место в компьютере не кончится). И у каждого файла всегда обязательно есть название. В файле может быть записано что угодно любой программой — мы, например, записывали в файлы текст простым текстовым редактором в предыдущих главах. И потом файл можно открыть любой программой — главное, чтобы программа, которая открывает файл, понимала тот «язык» (он называется «формат»), которым пользовалась программа, которая создавала файл. Файлы в компьютере можно складывать в папки, или директории\footnote{На самом деле, директория — тоже файл: в нём просто перечислен список, какие именно файлы лежат внутри.}. Если аккуратно разложить все файлы в компьютере по папкам, то в них существенно проще ориентироваться, чем если они лежат кучей в одной папке или в беспорядке в разных папках. 25 | 26 | Мы уже использовали объект, описывающий файл в Питоне, в предыдущей главе, таким образом: 27 | 28 | \begin{WINDOWS} 29 | 30 | \begin{listing} 31 | \begin{verbatim} 32 | >>> f = open('c:\\test.txt') 33 | >>> print(f.read()) 34 | \end{verbatim} 35 | \end{listing} 36 | 37 | \end{WINDOWS} 38 | 39 | \begin{MAC} 40 | 41 | \begin{listing} 42 | \begin{verbatim} 43 | >>> f = open('Desktop/test.txt') 44 | >>> print(f.read()) 45 | \end{verbatim} 46 | \end{listing} 47 | 48 | \end{MAC} 49 | 50 | \begin{LINUX} 51 | 52 | \begin{listing} 53 | \begin{verbatim} 54 | >>> f = open('test.txt') 55 | >>> print(f.read()) 56 | \end{verbatim} 57 | \end{listing} 58 | 59 | Так мы открываем для чтения файл «test.txt». Файл при этом находится в \emph{текущей папке}. Когда ты запускаешь Питон из консоли, то текущая папка остаётся той, которая была. Если ты не делал специальных манипуляций, то это просто домашняя папка. Если бы тебе хотелось напечатать файл «письмо.txt», который лежит в папке «почта», то надо было бы написать так: 60 | \begin{listing} 61 | \begin{verbatim} 62 | >>> f = open ('почта/письмо.txt') 63 | >>> print(f.read()) 64 | \end{verbatim} 65 | \end{listing} 66 | 67 | \end{LINUX} 68 | 69 | Файловый объект (он же объект типа \code{file}) не ограничивается только функцией \code{read}. В конце концов, если бы в папку с документами нельзя было добавить новых, мало пользы было бы от такой папки. 70 | 71 | Мы можем создать новый пустой файл, передав ещё один параметр функции \code{open}, вот так: 72 | 73 | \begin{listing} 74 | \begin{verbatim} 75 | >>> f = open('myfile.txt', 'w') 76 | \end{verbatim} 77 | \end{listing} 78 | 79 | Параметр «w» — сокращение от английского «write» — записать. Так мы Питону говорим, что нам из этого файла не надо ничего читать, надо только записывать. Поэтому если файл с таким именем уже есть, то он будет тут же очищен, а если его нет — то будет создан новый пустой. 80 | 81 | Можем что-нибудь записать в этот файл: 82 | 83 | \begin{listing} 84 | \begin{verbatim} 85 | >>> f = open('myfile.txt', 'w') 86 | >>> f.write('что-нибудь') 87 | \end{verbatim} 88 | \end{listing} 89 | 90 | Теперь открой этот файл в текстовом редакторе. Файл будет пустой. Почему — мы выясним чуть позже. 91 | 92 | \begin{WINDOWS} 93 | Если ты используешь в качестве текстового редактора блокнот, то закрой его, чтобы Питон смог всё-таки записать в файл всё, что мы просили. 94 | \end{WINDOWS} 95 | 96 | Чтобы в файле появилось всё, что нужно, надо сказать Питону закрыть файл. Потому что к этому моменту он запомнил, что \emph{надо будет} записать в файл \code{f} всё, что мы попросили, но ещё не записывал. Запоминать быстро, а записывать в файл — долго. По-настоящему Питон запишет в файл, только если программа завершится (то есть если закрыть консоль Питона, в которой мы открыли файл); или если помнить придётся слишком много — тогда какую-то часть Питон запишет в файл, а остальную будет всё ещё держать в уме; или если явно попросить Питон записать в файл всё, что нужно — например, функцией \code{close}: 97 | 98 | \begin{listing} 99 | \begin{verbatim} 100 | >>> f = open('myfile.txt', 'w') 101 | >>> f.write('что-нибудь') 102 | >>> f.close() 103 | \end{verbatim} 104 | \end{listing} 105 | 106 | Если теперь этот файл открыть текстовым редактором, то там будет записанный текст. Можно, опять-таки, воспользоваться Питоном для чтения текста: 107 | 108 | \begin{listing} 109 | \begin{verbatim} 110 | >>> f = open('myfile.txt') 111 | >>> print(f.read()) 112 | что-нибудь 113 | \end{verbatim} 114 | \end{listing} 115 | 116 | После того как файл закрыт функцией \code{close}, в него больше нельзя ничего записать. Если потом захочется дописать что-то в конец этого файла, то надо его снова открыть, но вот так: 117 | 118 | \begin{listing} 119 | \begin{verbatim} 120 | >>> f = open('myfile.txt', 'a') 121 | \end{verbatim} 122 | \end{listing} 123 | 124 | Параметр «a» — сокращение от английского «append», то есть «добавить». Если теперь записывать в файл \code{f}, то всё записанное появится в конце файла после всего того, что там уже было. 125 | 126 | \begin{center} 127 | \fbox{\colorbox{PaleBlue}{\parbox{.85\linewidth} { 128 | \subsection*{Почему бы не записывать сразу?} 129 | Наверное, кажется странным, зачем такие хитрости с запоминанием и записыванием только потом. Простой ответ — чтобы было быстрее. 130 | 131 | Дело в том, что записывать в файл может быть в тысячу раз медленнее, чем запоминать (в \emph{оперативную память}). Чтобы хоть как-то это исправить, в файл пишут сразу большой кусочек данных за раз, так получается быстрее. Всё, что меньше, чем размер кусочка, Питон держит в памяти. Ещё бывает, что нужно что-то записать в файл, потом в другом месте программы это прочитать из файла, а потом файл и вовсе удалить за ненадобностью. Так вот если данных немного, то их можно и совсем не записывать в файл, а только запомнить, что сильно ускоряет работу программы. Вообще, подобным образом с файлами обращается не только Питон, но и большинство программ. 132 | }}} 133 | \end{center} 134 | 135 | \section{Как ещё развлечься} 136 | 137 | \emph{В этой главе мы обсудили, что же такое файл, наконец, а ещё как файлы читать и как в них записывать. Узнали, что Питон записывает в файл не сразу и почему он так делает: чтобы было быстрее}. 138 | 139 | \subsection*{Упражнение} 140 | 141 | Часто людям приходится копировать файлы, и ты наверняка с этим сталкивался — например, копируя файлы на флэшку, чтобы отнести в школу. 142 | 143 | Напиши функцию \code{copy} с двумя параметрами: именем файла, который надо скопировать, и именем нового файла. 144 | Функция должна посчитать количество строк в файле и потом скопировать один файл в другой, строчка за строчкой, выводя после каждой строчки, сколько ещё осталось копировать. 145 | 146 | Чтобы перебрать все строчки файла \code{f} одну за одной, надо использовать вот такой код: 147 | \begin{listing} 148 | \begin{verbatim} 149 | for line in f: 150 | ... # очередная строчка файла записана в переменную line 151 | \end{verbatim} 152 | \end{listing} 153 | 154 | Чтобы ещё раз перебрать все строки файла, надо его ещё раз открыть. 155 | 156 | Функция \code{write} возвращает значение: количество записанных символов. Если оно печатается в консоль при выполнении функции, просто присваивай это значение какой-нибудь переменной (например, так: \code{w = newfile.write (line)}). 157 | 158 | Чтобы проверить, работает ли функция, вызови её: 159 | 160 | \begin{listing} 161 | \begin{verbatim} 162 | >>> copy ('myfile.txt', 'mynewfile.txt') 163 | 164 | \end{verbatim} 165 | \end{listing} 166 | 167 | Открой файл «mynewfile.txt» в текстовом редакторе и проверь, что внутри у него то же самое, что и в «myfile.txt». Если нет, проверь, не забыл ли ты закрыть новый файл (\code{close}), чтобы Питон записал туда всё, что держит в уме. 168 | 169 | \newpage -------------------------------------------------------------------------------- /ru/figure36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gluk47/swfk/f6248872d6085f6018621caeae84dbfcf61f0bbf/ru/figure36.png -------------------------------------------------------------------------------- /ru/frontmatter.tex: -------------------------------------------------------------------------------- 1 | \pagestyle{empty} 2 | \frontmatter 3 | \begin{titlepage} 4 | \begin{textblock*}{210mm}(-30mm,0mm) 5 | \includegraphics[width=0.9\paperwidth]{../en/cover.eps} 6 | \end{textblock*} 7 | \begin{flushright} 8 | \vspace{30mm} 9 | \begin{WINDOWS} 10 | \includegraphics[width=40mm]{../en/windows-edition.eps} 11 | \end{WINDOWS} 12 | \begin{MAC} 13 | \includegraphics[width=40mm]{../en/mac-edition.eps} 14 | \end{MAC} 15 | \begin{LINUX} 16 | \includegraphics[width=40mm]{../en/linux-edition.eps} 17 | \end{LINUX} 18 | \end{flushright} 19 | \end{titlepage} 20 | %todo Finish translation 21 | \noindent 22 | \textsf{\emph{Snake Wrangling for Kids, Learning to Program with Python}}\\ 23 | by Jason R. Briggs\\ 24 | перевод на русский язык:\\ 25 | Кочетов Е.\,М. \\ 26 | \\ 27 | Version 0.7.7 28 | \\\\ 29 | Copyright \copyright 2007, 2016\\ 30 | \\ 31 | Cover art and illustrations by Nuthapitol C.\\ 32 | \\ 33 | \noindent 34 | \textsf{\emph{Эта книга была существенно переработана и дополнена автором; в новых главах рассказывается о программировании графических игр на Питоне. Также в неё были добавлены задачи, чтобы прочитанные знания не высыпались из головы слишком быстро. Переработанная книга \href{https://toster.ru/q/50630}{не была переведена на русский} (по крайней мере, на 2016 год) и была издана под названием \href{http://nostarch.com/pythonforkids}{Python for Kids} издательством No Starch Press. Официальный сайт автора находится \href{http://jasonrbriggs.com/python-for-kids/}{здесь}, там тоже написано про эту книгу.}} 35 | \\ 36 | \\ 37 | \linebreak 38 | \noindent 39 | Website:\\ \href{http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids}{http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids}\\ 40 | Github с переводом книги:\\ 41 | \url{https://github.com/gluk47/swfk/tree/master/ru}\\ 42 | \\ 43 | \noindent 44 | Thanks To:\\ 45 | Guido van Rossum (for benevolent dictatorship of the Python language), the members of the \href{http://www.python.org/community/sigs/current/edu-sig/}{Edu-Sig} mailing list (for helpful advice and commentary), author \href{http://www.davidbrin.com/}{David Brin} (the original \href{http://www.salon.com/tech/feature/2006/09/14/basic/}{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.\\ 46 | 47 | \noindent 48 | License:\\ 49 | \\ 50 | \includegraphics[width=40mm]{../en/by-nc-sa.eps}\\ 51 | This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. To view a copy of this license, visit\\ \href{http://creativecommons.org/licenses/by-nc-sa/3.0/nz/}{http://creativecommons.org/licenses/by-nc-sa/3.0/nz/} or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.\\ 52 | 53 | \noindent 54 | Ниже приведены основные положения лицензии.\\ 55 | 56 | \noindent 57 | Лицензия позволяет: 58 | \begin{itemize} 59 | \item \textbf{Делиться} — копировать, распространять и передавать эту работу, 60 | \item \textbf{Изменять} — адаптировать эту работу. 61 | \end{itemize} 62 | \noindent 63 | На следующих условиях: 64 | \begin{description} 65 | \item[Attribution.] Обязательно явно указать авторство этой работы таким способом, как этого просит автор (и так, чтобы не казалось, что автор прямо поддерживает вас или вашу работу, основанную на его). 66 | \item[Noncommercial.] Нельзя использовать эту работу и основанные на ней в коммерческих целях. 67 | \item[Share Alike.] Если вы изменяете, перерабатываете, адаптируете и распространяете эту работу, обязательно распространять её на условиях этой же лицензии. 68 | \end{description} 69 | 70 | \noindent 71 | При любом использовании и распространении необходимо донести до получателей условия лицензии на эту работу.\\ 72 | 73 | % Я не юрист и не понимаю смысла слов ниже, так что переводить не буду. 74 | \noindent 75 | Any of the above conditions can be waived if you get permission from the copyright holder.\\ 76 | 77 | \noindent 78 | Nothing in this license impairs or restricts the author's moral rights.\\ 79 | 80 | \vspace*{4cm} 81 | \begin{center} 82 | \includegraphics[width=5cm]{../en/python-powered.eps} 83 | \end{center} 84 | 85 | \mainmatter 86 | 87 | \pagestyle{plain} 88 | 89 | \pagenumbering{roman} 90 | \tableofcontents 91 | -------------------------------------------------------------------------------- /ru/preface.tex: -------------------------------------------------------------------------------- 1 | % preface.tex 2 | % This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 New Zealand License. 3 | % To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/nz 4 | % or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. 5 | 6 | 7 | \chapter*{Вступление}\normalsize 8 | \addcontentsline{toc}{chapter}{Вступление} 9 | \begin{center} 10 | {\em Пара слов для родителей...} 11 | \end{center} 12 | \pagestyle{plain} 13 | 14 | Уважаемый родитель или иной управляющий компьютером! 15 | 16 | Чтобы ваш ребёнок смог начать знакомиться с программированием, вам нужно установить Python на компьютер. Эта книга была недавно обновлена до версии Python 3.0, самой новой и несовместимой с предыдущими, так что если у вас установлена более старая версия Pyhton, вам стоит скачать и более старую версию этой книги. 17 | 18 | Установка Python — достаточно простая задача, но есть несколько тонкостей — в зависимости от используемой операционной системы. Если вы только что купили сверкающий новый компьютер и не имеете никаких идей, что с ним делать, а предыдущее предложение начало вызывать у вас нервную дрожь или холодный пот, то, пожалуй, лучше вам найти кого-то, кто сделает это за вас. Установка Python может занять от 15 минут до пары часов в зависимости от скорости интернета и компьютера. 19 | 20 | \begin{WINDOWS} 21 | 22 | Прежде всего, надо сходить на сайт \href{http://www.python.org}{www.python.org} и скачать оттуда самую свежую версию Python 3. На момент написания книги это версия 3.5.1, вот установщик для 64-битной ОС: \url{https://www.python.org/ftp/python/3.5.1/python-3.5.1-amd64.exe}, а вот — для 32-битной: \url{https://www.python.org/ftp/python/3.5.1/python-3.5.1.exe}. Если вы не уверены, что значат слова «32-битной», то скачивайте как раз 32-битную версию, она везде запустится. 23 | 24 | Запустите скачанный установщик и нажимайте «Далее» до готовности. Питон установится в папку вроде «\code{c:\textbackslash Python35}». Лучше не устанавливать Питон в папку, в имени которой или в пути к которой есть пробелы, это может вызвать некоторые трудности потом. 25 | 26 | \end{WINDOWS} 27 | 28 | \begin{MAC} 29 | 30 | Скачайте и установите python 3 отсюда: \url{https://www.python.org/downloads/mac-osx/}. На момент написания книги самая свежая версия — 3.5.1, вот она: \url{https://www.python.org/ftp/python/3.5.1/python-3.5.1-macosx10.6.pkg}. 31 | 32 | % Если кто-то что-то хочет сюда добавить, welcome. У меня нет мака, так что подробнее я не могу описать. В оригинале автор делал подобие ./configure && make && make install, что для мака уже не актуально. 33 | 34 | \end{MAC} 35 | 36 | \begin{LINUX} 37 | 38 | Прежде всего, скачайте и установите последнюю версию Python 3 для вашего дистрибутива. Дистрибутивов очень много, так что инструкции для всех тут привести не получится… да и скорее всего, если вы используете Linux, то уже знаете, как это сделать. Наверное, вы даже возмущены самой идеей того чтобы рассказывать вам, как что-либо устанавливать, так что тут я остановлюсь. 39 | 40 | \end{LINUX} 41 | 42 | \note{После установки…} 43 | 44 | …Вам, возможно, придётся в течение первых пары глав посидеть с ребёнком рядом, но после нескольких примеров ему будет только приятнее читать книгу самому (с компьютером вместе). Нужно рассказать ребёнку, как вводить команды в консоль, как пользоваться текстовым редактором (наподобие блокнота; OpenOffice никак не подойдёт), открывать и сохранять файлы в этом редакторе. Всё остальное расскажет эта книга. 45 | 46 | \vspace{12pt} 47 | \noindent 48 | Спасибо за уделённое время; с наилучшими пожеланиями,\\ 49 | КНИГА. 50 | -------------------------------------------------------------------------------- /ru/version-linux.tex: -------------------------------------------------------------------------------- 1 | \excludecomment{WINDOWS} 2 | \includecomment{LINUX} 3 | \excludecomment{MAC} 4 | -------------------------------------------------------------------------------- /ru/version-macos.tex: -------------------------------------------------------------------------------- 1 | \excludecomment{WINDOWS} 2 | \excludecomment{LINUX} 3 | \includecomment{MAC} 4 | -------------------------------------------------------------------------------- /ru/version-windows.tex: -------------------------------------------------------------------------------- 1 | \includecomment{WINDOWS} 2 | \excludecomment{LINUX} 3 | \excludecomment{MAC} 4 | -------------------------------------------------------------------------------- /ru/version.tex: -------------------------------------------------------------------------------- 1 | version-macos.tex --------------------------------------------------------------------------------