Download as pdf or txt
Download as pdf or txt
You are on page 1of 130

Snake Wrangling for Kids, Learning to Program with Python

by Jason R. Briggs

Version 0.7.7

Copyright

Published by... ah, no one actually.

Cover art and illustrations by Nuthapitol C.

Website:
http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids

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

License:

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
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.
Below is a summary of the license.

You are free:


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

Under the following conditions:

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

Share Alike. If you alter, transform, or build upon this work, you may distribute the
resulting work only under the same or similar license to this one.

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

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

Nothing in this license impairs or restricts the authors moral rights.


, , 8, 8 ,
, , 8, 8
, 8 ,
, 8 , , 8 , 8

, 8 ( ( ( ( , )

# : & , ( ',
: ( , ( ,, 8- , 8, 8
se of T. (Brackets
se of T. (Brackets) , 8
se of T. (Brackets,

( , 8 2 :
, 83
, 8 , ( ( 4

, 8 :

se of T. (Brackets) ,
, 3 84
(
se of T. (Brackets) 3
( 8
( ,

, ( 2 , , , ( :) , , :
( (
- ' ( @... ...

( / / ( -- ,
, 8 , , 8 4 ( , 84 , , 8 , 8 ( ( , 8 ( , 84 ( F 4 , 8 ( ( , , , 8 2 , 84
( F , 8 H ( , , 8 ( , 84 ( J4 3, 8 4 :) , 8 , 8 ( , 84 3, 8 , (
3, 8F , 8 ( , , 8 , 8 , 84 3, 8 , 8 ( 4 ( , 8 . , :)
, 8 , 8 , ( , 8#2428 , , 8 , 8 , 8 ,
, , 8 ( , 84 3, 8

, 8 4 ( , 8 , 8 , 8 ( ( , , 8 , 8 ( &3 , 8


4 , 8 ( -2 , 8 ( @ , 84 3, 8 ( 3 , 8 ( , & 4 , 8
( , ( ( , 8 ( (
se of T. (Brackets) , 8 , 8@ , ( ( , 8 ( , 84 3, 8 4 ( 4 3, 8 (
, 8#2428 ( , 8 , 8 , 8 W
se of T. (Brackets, X , 84 , 8 , 84 -# ( 4 3, 8F (
, 8 Y, 8 , 8 , 8 , 3 4 :) , 8, 8 , 8 , 8 , 8 , 8, 8 , 8

, 8 . (, 2, 8 , ) :) 4 , , 8 , , 8 ( , 84 3, 8 ( , 84


, 8 ( , , 8 [
se of T. (Brackets , 8 , , 8 , 8 44 8 ( ( , 8 , 8
se of T. (Brackets ,
, 84 , 8 , 8 ( - ( ( - ( , ( a ( , 8 :) ( 4 ( , 8 , 8 ( , 8 , , 8
& , 8 4, 8 ( , 8 ( ( &3 8 3, 8 , 8 4 3, 8 , 84 , 8 & , 84 , 8 , 8@ ( , 84 3, 8
, 8 , 8 , 8 ( , , 8 , 8 . , 8 (

, 8 , 8 , 8 ...


, 8 ( & , 8 :) , 8 , 8 , 8 , , 8 , , 8 , , 84 3, 8 (
( , 8 ( 3 , 8, 8 , 8 , ( , 8 ,2 , 8 , 8 3 4 , 8 , ( , 8 ( , 8 , 84 , 8
, 8 , , , 8 2 , 8#, 82 , 8 ( , 84 3, 8 8- , 8 ( , (Text Editor) &3 , 84 3
, , 8m n
se of T. (Brackets) , 8,2 , 84 ,2 , 8, , , , , 8 2 4 , 8 , 84 3, 8 , 8, 8 , 8 Y, 8 ,2
( , , , , 8 2 , 8 , 8 , ( @ &3 :
se of T. (Brackets) , 4

se of T. (Brackets) , 4& ( , 84 3, 8 , 8 ( , , 8 , 8 , , , 8 2 , 3
- q ( r , 8 , 8@ , 8 , ( , 8, 8 FJ - , 8 ( 4
( , 84 , 8 (

, 8 # & , :) , 3, 8 ( 4 :) ( :)


, #8, 8

. , , 8, 8 , ( , ... ...


. - ( , 8 ( @
. ( ( 2 ( - , 8, H, 8 8 , 8
. 4 , 8 (
. 4 ( v48 , 8 ( ...

. , ( 4...
. 8 (Brackets) &3 '', 8 , 8 , 8 ( 3 4 '' (Order of Operations)
. - ( , 8 , 8 , 84 ( [ ( @
. - ( , 8 , 8 &3
. , 8 ( a
. ( a , 8 ( @ q
. r ( 4 ( X4 (
. , 8 4 (
. , 8, ( , 8 (

. ( @ :) :) 8 ( 4 8...


. 4 r

. , 8 , 8 , 8 ( 4 ...


. ( :) ( (Do this... or ELSE) !!!
. ( , 8 .. ( , 8 ... , ( , 8 ... :) ( , 8 !!! (Do this... or do
this... or do this... or ELSE!!!)
. , 8 42 , , 8
. 8
. , 8 2 & 8 ...?

.
. ( 2, 8 ?
. , 834 , 8 ( , 8 , 8 ( @
. ( , 8 r , 8

. &4? 4 3, 8 ( , 8 &3 , 8 & !!...


. ( ( , 8, (Bits and Pieces)
. ( , (Modules)
. , 8, ( , 8 (

.
se of T. (Brackets) ( , 8 ( @ &
. F, 8, 8
.
.
. ( , 8 -
. ( , 8 (

. ( ( (
se of T. (Brackets) ...
. 4
. ,
.
. H, 8 , 8 ( ( ( , 8 ( 2)
. , 8H
. -
. , 8
. q ( & ( , 8
. ( ( , 8-
se of T. (Brackets (Reacting to events. . .)

. , 8 ... ... ...

, 8 ( ( r A , 8 , 8 # , #3 ... ... ...

, 8 ( ( r B , 8#2 ( 2 ( 4
se of T. (Brackets) , 8 ... ... ...

, 8 ( ( r C , 8 , 8 ( @ ( , ... ... ...

, 8 ( ( r D '', 8, ( , 8 ( ''


&

, , 8, 8 ,
( , ... ...

4 , 8 ( , 8 , 8 Y, 8 8 (


se of T. (Brackets 4 , 8 ( , 83 ( , 8 ( @ ( , 8 , 8 ( , 8
, ( 3, 8, 8@ 4 , 8 3, 8 4 ( ( W , 8 4 , 8 , 8 , 8 , 8 Y, 8 8 (
se of T. (Brackets
4 , 8 ( , 8 4 , 8 ( , 83 , 8 4 ( , 8 ( ( 4 , 8 & ( ( , 8 , 3 28
& 4 , 8 ( ( , , 8 ( ( ( , 8 , 8 , 8, 8 4 @ ( ( , 8
, 8 (3 ( , 8 4 ( 4 , 8 4 ( , ( ( , 8 ( @, 8 , 8 &3 4 , 8
( ( , 8@ , 8, 8 (
se of T. (Brackets 4 :) J ( ( , 8 , 8 , 83 :)

4 ( ( 3, 8F ? ( ( , 8, 8 ( , 8 , 8 4


4 3, 8 , 8 3 ( ( 3, 84 , 4 ? , 8 , 8 , 84 , 4 ( , , 8 (
( , 8 !!! ( - , 8@ , 8 ( 4 ( , 8, 84 , 8F , 8, 8 , 8 , , 8 , 8
, 8 ( , 8 3#42 ( , 8 , 84 ( , , 8 , 8 , 4 , 8 4 , 8
( , 8 ( , 8 :) , 3 ( F ( 3, 84 Y4 , 8@ ( -4 ( @
, 8@ ... @ ( , 8@ , 84 , 8 , 8 4 ( , 8H , 8 4 3, 84 ( -q ( 4
, 8 ... 3 3 3 ( , ( 4& ( , 8 ......

, 8@ J , 8 Y4...........

- , 8, 8 , 8 ( ? & , 8 , , 8 4, 84 , 8 ( ( , 84 , 8 ( , 4 ( 4 , 8
4 , 8 ( , 84 , 8 , 8 ( 4 ( , , 8 ( @ , 84 , 8 , 8
- 8 ( ( , , 8 , 8@ ( , ( , 8, ( , 8 4 , ( , ( , 8, & ( ,- , v
, 8 , , 8 ( , 8 ( 4 ( ( , 8 , 8 , ( W [ , 8 2 , 8 :) [ , 8 ( , 8 , 8
X& ( 4 , , 8 , 8 [ , 8 2 , 8 X& ( 4 , 8 ( , 8 -, 8 , [ , 8 2 , 8 )
@ ( @ ( ( , , 8@ , 8 4 , ( , ( , 8, & ( ,- , 8, , 8 & ( 4 , 8
, 8
se of T. (Brackets) , 8 ( , , , 8 &3 , 8, 8 8 3 ( , , 8 ( @ , 84 , 8 (

4 ( ( ( - , 8 ( , 4 4 , 8@ ( @ ( F -, 8 4 4 (


( @ , 8, , 84 , 8 , 8 ? ( ( 4 ( , , ( , 8 ( , 8 ( 4
3, 84 4 3, 8 , 8 , 8, #& H ( r, 84 @ , 8 ( , 8 4 ( , 8 , 84 4 ( , 4 , 84 , 8 , 8
, 8, , 8 , 8 , 8 4 ( , , 8 , 8 ( , 84 3, 4 , 8 ( , 8 , 8 ( , 8
( , 84 3 :) ( , , 8 ( 3 ( ( 38 ( , 238 4 ( 238

4, 8 ( , 8
se of T. (Brackets) , 8 @ , , !


( @ ( @

4 , 8 ( , 84 ( , ( , 8 :)


, :) [ , 8@ ( , 8
( @ ( , , 8 , 3 4 (
( , 8 , 4 , ( , ( - ( , , , 4 ( ,
( , , 84 ( , ( , 8@ ( 4 (
( , X& ( 4 , 8 ( 4 , 8 (
2 8 , 8 4 , 84 , 3 4 , 8 ( , ( - ( , , 8
( , 8@ 4 3, 8F , 8 ( , 84 3, 8 4
( , 8 3, 84 ( , ( , 8@
( & &3 , 8 8- , 8 W
se of T. (Brackets, 4
( , 84 3, 84 ( ( , 8@ ( , , 8
( @ Y , 8 , , 8 4 ( , 8

& , 8 3, 8F, 4 ( ( ( , ( ( , 84 , 8 , 8 4 3, 8 4 ( 4 , 8 8 ,


, 84 , 8 , 8 3, 84 , 8 , 8 4 ( ( , 8 :) ( ( , 8
se of T. (Brackets) , 8 , 4 , 8 :) , 8 , 8
(web page) X4 ( , 8
se of T. (Brackets) , 8 ( ( , 84 , 8 , 8 , 3 , 8 & 4 8 , 84
, 8 , 8

( , 8 3? ( ( ( , ( , 84 ( F, 4 4 ?

. - ( , 8 ( @

4 4 , 8 4 ( , 84 , 8 , 8 ( , 8 ! , 8 ( & , 8 , 8 , 8
4 ( , 8 2 4 4 ( , 8 , 84 , 8 , 8 , 8 , 8 , 8 ( ( , , 8, 8 , Y4
, 8 @ ( , 8 - , 8 , 8 3 ( ( 4 , 84&, 8 , 84 , 8 , 8 , 8
, 8 , 8 , 8 ( , 8 4 ( 4 , 84 , 8 , 8 , , 8 (
- , 8@ ( W 4 ( ( , , 8 ( , 8 - , 8@ ( , 4 ( , 8 - , 84
, 84 , 8 , 8 , 8 , 8 8 ( , 8 8 - , 8 , - 48 ( ( 3J8 -
, 8 , 8 8 ( - , 8 2 , 8 , 8 - &3 , 8 , 8
& , 8 3, 8F ( , , ( , , 8 - , 8 , 8 , 84
( , , 8 , 8, 8@ ( - &3 , 8 , , 84 , 8 , 8 ( , , 8 &4 -
( ( - ( , 8 ( , ( 4 ( ( , , 8 ( ( - , 8 ! 3 3 3 )

( @ ( @ ( ( - , 8 , 8 3, 84 , 8 , 8 Acronym , 8 & ( , 8 ( W4


( ( -, 8 , 8 , 8 ( ( - , 84 , 8
( @ , 82 , 8, 8 ( 4 ( ( (+) , ( (#) 4 3, 8 ( 3 Y , 8 4 , 84 :)
( ( ( - 4 ( , 8, 84 , 8 , 8 & , 8 ( , 8 ( ( , 8 & , 8 ( -
, 8 3 2 , 8 4 , 8 2 & ( Y, 8 , 8


4 3, 8 ( .......... !!

, q- &m, 8 ( , , 8 , ( - ( @ ( @ , 8 , 8 &4 3, 8 , 8 , 8@ , 8, 8 (
3, 8 , 8F 3 , ( , , 8 , , 8 , 8 , 8 , 8@ 4 , 8 & ( , 8 ( , 8
, 8 , 84 , 84 , 8 @ 4 3, 8 , 8 ( , , 8 - , 84 , 8 , 8

se of T. (Brackets) , 8 , 8 , 8 ( 4 3, 8

. ( ( 2 ( - , 8, H, 8 8

, 8

- , 8, 8 , ( , , 8, 8 ( @ ( , , 8, 8 ( @ 4 ( , , 8 ( ( (


- F , 4 ( ( ( -, 8 ( 4 , 8 - @? 4 3, 84 4 , 8
, 8 (
se of T. (Brackets , 8 , 8 ( ( ' ( , 8 ( , , 8@ , , 8 , 8 2 ( (
( ( - ( 3, 8, , 8 ( 4 3, 8 , , 8@ ( , 8 ( ( - & , 8 - ( , 8 , 8
, 8 - , 84 3, 8 , ( , 8 , 8 ( ( (
- , 8@ ( W , 8 @, ( , , 8 &4 , 8 - 3, 8, 8@ , 8

( , ( , , 8 , , , 8 2 4& 8 , 3#, 842 4 ( ( ( ( @


( W , 3#, 842 44 , , 8 :) 4 , 8 , 8 , 3 & , 8

.... 4 / ( ( ( 4 , 8 ( , , 8F 4 Y, 8 ( ( , 8 , 8


, 84 '' ( -- , 8 ( 4......'' , 8 , 84 , 8 , 8 , 4 4 Y , 3 & , 8

4 Y ( - , 8 , 8 , 8, 8 , 8@ ( , 8 , 8 ( ( :) 4 , 8 ( 2

( . ( - :) , 8 , 8,


& ( , 8 ('Konsole', 'rxvt', xterm' , , 8 ( , 8 ( ) &3 , 84 3, 8
, ( 2 3, 8 4 ( , , 8 , 8 4 Y , 84 , 8 , 8 , 8 , , 8 (
, 8, 8 , 8@ , 8 ( , 4 ?

( 2 ( ( , 8 , 8 , 8 python ( H ( 4 ( &484)


se of T. (Brackets , 8, 8 ( .
, 84 ( @ , 84 , 8 , 8

, 8, 8 ( , 8 2 , , 84 ( , 8 ( 3 4 ( ( @ Y, 8 , 8 F 4 3, 8 ( 4


/ ( , 8 ( , 8 , 8, 8 ( , - , 8 , 8@ 4 (
( , 8 , 8 ? 4 , 8 :) ( 4 , 8 , 8 , 84 , 8 , 8 3, 84 , 8 , 8
( 4 ( 4 , 8 ( , 8 , 8@ ( ( -, 8 , 8@ 4 , 84 ( @ , 8, 4 ( , 8
( & , 8 , 84 , 8 , 8 . - 3 , 8, 84 , 8 , 8 , . 4 &3 , 8 ( 3, 84 , 8 , 8
& , 8
se of T. (Brackets)
se of T. (Brackets) ( 4 ( , 8 - , 8 - , 8 , 8, 8 ( , 8 2 8 , 8
, 8F , 8 4 ( ( , 8 , 8, 8 ( , 8 2 8 , 8 , 8 ( , 84 , 8 , 8

. 4 , 8 (

- , 8 3 , 8 ( , 84 , 8 ( , 8, 8 4 ( , 8 , 8, , 84 , 8, 8 @ , 8
, 8, 3, 8F , 8 , 8
se of T. (Brackets, ( , 8 4 ( , 8, , 8 (

se of T. (Brackets, , 8) 4 ( ( ' , ' (prompt) , 8 , 8 , 8 , 8, , 8 ' , ' 3, 8F , 8 , 8 ( 4 ( 48, 8
( 4 ( H3 ( (>)

se of T. (Brackets) , 8 ( , 84 3:

>>>

, 8 ( , 8 , , 8 , 8 (


se of T. (Brackets, ( , 8 , 8, @ :) :) ( , 8 , 8 (
3#, 842 ( , 8 , 8 , 8 , 3 , , 84 4 , , ( , 8, , 8 , (>>>)
, 8 , 8 4 3, 8 ( , 8 & ( ( , 8 , ( , 8 ?

print("Hello World")

, 8, 8
se of T. (Brackets, ( , ( ( () ( , 84 3, 8 ( 3, 8
se of T. (Brackets 8 , 8 ( @
( , 8 , 8 , 8:

>>> print("Hello World")


Hello World


se of T. (Brackets)
se of T. (Brackets) , 8 , H 2 3, 8F , 8 , 8,
se of T. (Brackets, :) 4

( -J!! 8, 8 , 8 ( ( 4 ( ( , 84 , 8 & ( , 8


se of T. (Brackets) , 8 , 8 (
se of T. (Brackets (print) 3, 8F
, 8
se of T. (Brackets) 2 8 , 8 & 3 , 8 428, 84 4 &4 3, 8


. 4 ( v48 , 8 ( ... ...

- @, ( ( , ?

, ( 4 ( 4 , 8
se of T. (Brackets, ( , 84 3 4 3, 8 4 - ( @ , 8
( , , 8 4, 84 , 8 8 3, 8 ( 3 :) 4 ( ( ( ( , 8 @ (
&3 , 8#, 82 4 , 8 , 8 , ( ( , 84 3, 8F 4 3, 8 , 8 ( , 8 3

4 ( , , 8 ,2 , 8, , & ( , 8 ( &3 , 8 ( , 84 , 8 & , 8 , 8 & , , 8
se of T. (Brackets
4 ( , 8 , 8@ 4 3, 8 4 ,2 , 8, , 3, 8F ( , 8 , 8 ( (
, 8 2 , 8@ F , 8 , ,2 , 8, , , 8 , 8 , 8 4 ( (
se of T. (Brackets , 8 , 8H
, 8 ( , 8 - ( , 8 (
se of T. (Brackets 3, 8 4 , 8 ( -2 , 8 , ( #, 8 4
( , 8 3, 8 ( 3, 8, , 8 4 3, 84 , 8 , 8 , 8H ... , 8 Y , 8H ( ( #, 8!!!
, 8 ,
se of T. (Brackets) & ( , 8 ( , 8 , , 84 4 , 8 , 84 3, 8 ( @
, , & , 8 , 8 4 , 8 4 ( -, 8 , 8 ( F!!

. , 8 , 8 ( , 8 , ( , 8 4 , , 8 4 3, 8 4 , 8 , !


- ( &, ( &3 :) (
se of T. (Brackets ( , 8 ( , 8@ 4 3, 8
, 84 , 8 4

( ( , , (Text Editor) , 8 4 , 8 2


( , 8, , 8 ( , , (Text Editor) &3 , 8 4, 8 , 8, , 8 , 8#2 ( ( 4 (
se of T. (Brackets
se of T. (Brackets, (
( :

print("Hello World")


File , 84 ( , 8 Save , 8, 8 , , ( , 8 4 hello.py , 8
Home folder , , 8 , 8, 8 , , 8 :) 2 H4 , Home :) (
, 8 4, 8 , 8 , 84 ( 2 & ( , 8 ( (Konsole, rxvt , 8#, 82 &3 , 8 @) , 8
, 8 , 8 :

python hello.py

, 8 , 8, , 8 , 8, 8


se of T. (Brackets, , , 8 , , 8 , 8 3, 8, 8@ Hello World ( .

( . (
se of T. (Brackets) , 8 , 8 (

, 8 , 8 ( , 8 , 8@ 4 4 , 8 -, 8, 8@ ( ( ,


( , 84 3 4 &[ , 8 , 8@ 4 , 8 4 , 8 , 3 , 8 ( , 8, 8@ , 8
, , 8 ( , 8 4 r , 8 , 8 , 84 , ( ( , 8 ( @ 4 -
, 8 4 ( , 8 ( , , 8 , 8 4 , 84 4 , 8 , 8 ( 4 , 8 4
3 , , 84 3 , , 84 4 , 8, 8 ( , 8 , 8

3 , 84 ( 3, 8

, , 8, 8 ( ( ( 4 , 8 4 , & ( , 8 ( , 8


, 8 ( @ ( ( , , 4 , 8 , 8 , 8 428 & , 8 , 8 , 8, &3 , 8
( @ , 8 8 , 8 , 8 ( - , 8 ( ( X4 ( , 84 3


( v48 &

, ( 4...

4 ( , 84 , 8 , 8 , , 8 . , 8 4 3? ( 4 , 8 ( , 84 , 8 4 3, 8


4 ( ( , 8? ( & , 8 &3 , 8 r , 8 ( 4 ( ( ( 3, , 8 , 8 - , 8 3
2 , 8 , 8 , 8 , 84 , 8 , 8 4, 8 , - , 8 r , 8
se of T. (Brackets) ( , 84 , 8 4, 8 , 8
, 8 , 8, , 8 , 8, &3 , 8 , 8 , 8, , 8 (
, 8 ( , 8 , , 8 , 8, , , , 8 2 , 84 & ), , 8, , 8 (
se of T. (Brackets, ,
, 84 , 8 , 8
se of T. (Brackets, , , 8 8 * 3.57 , 8 , 8 ( , 8 ,2 , 8
se of T. (Brackets 8 , 8, 8 :

Python 3.0 (r30:67503, Dec 6 2008, 23:22:48)


Type "help", "copyright", "credits" or "license" for more
information.
>>> 8 * 3.57
28.559999999999999

, 8 , 8, , 8 :) &3 3 * (4 ) ( ( ( ( @ ( @ ( , 8 , 8,2 ( , 8 , 8 shift
8 8 , 8, 8 ) , 4 , 8 ( , 84 ( 3, , ( , 84 X &3 , 8 ( (
, 8 , 8 X , 8 * &3 , 84 3 (* , 8 X &3 , 8 ( , , 84 , 8 , 8 4 ( (
, 84 , 8@ , , 8 ( 3
se of T. (Brackets) X ( , 84 , 8@ ) , 8 , 8 , 8 8- , 8 (
( 8?

, 4 4 , 8 ( 4 , 8, , 8 ( (


se of T. (Brackets) , 8 ( 3, 8, , 8 @ 4 ( ( 4
, 8, , , 8 H ( , 8 4 3, 8 @, 8 4 ( 4 , 8 ( ( 3, ( 4 ( , 84
( 4, 8 ( , 8? 4 ( 3, 84 ( , 8:
(+) X

, 8 ( 4, 8 , 8 !!!!

4 ( ( ( & , 8 , 8 8X3.57 4, 8 , 84 , 8 , 8:


28.56

4 3, 8 , 8 , 8 3 ? 4, 8 ( , 8 , 8 ?

, , 8 4 3, 8 ( , - ( ) ( ( , & - ( ) )


( , 8 :)- , 8 , 8 , 8, 8 - ( ) , 8 3 ( , 8, 8
se of T. (Brackets
(float number) , 8 ( , 8 , 8 , 8@
4 , 8 :) ( ( , 4 , 3, 8 , 8 :) , 8
, 8 , 84 3, 8, ( , 8 - ( ) ( , 8 , 8 2
- ( , 8 , -- , 8 4 , ( W
se of T. (Brackets)
se of T. (Brackets) , , 84 , 8 , 8


, 8 , , 8 , 8 @, 8 , ( , 8 3, 8, 8@ 4 ( , 834
( 3, , 8 , 8 ( 2 4 , 8 (+) , , 4 4 , 8 ( 3, 8:

( , 8 & , 8 , 8 :) ( 4 ( , 8 , 3 ( ( 3, ( , 8, , 8


- , 8 , 84 , 8 ( :

>>>(200+300)* 12
6000
>>>500* 12
6000

, 8 , ( 4 ( , 8, 4, 8 ( 3, 8 ? @ , 8 4 3 , 84 4 , 8 ? , 8 (


4 ( - - , 8 ( , 84 , 8 ( , 8 , 8 ( , 8, ( ( :

>>> (200 + 300 - 250) * 12


3000

2 , 8 ( , 8 , 8 @, 8 , ( , 8 , 84 3, 8 4 3 , 84


@ , 8 , 8 , 8 & , 8 &3 , 8 , 84 , 8 ( (
, 8 , 8, , 8 8- , 8 , 8 , 3, 8

, 8 , 8, , 8 , - ( - , 8), , ( , 8 , 84 , 8 , 8 , 8


, , 8 , 84 , 8 , 8 , , 8F , 8 , , 8 , 8 , 8 ( ( 4 ( 3, 8, , 84 , 8 , 8 (
, 8 , , , 8 , 8 , 8 ( @ q ( ( ( 4 ( , 8 , , 8 , 8 ( ( 4 3, 8
( H4, 8, 8 ( , 8 , 8 , 8 , 8 , 8 ( ( 4) ( , 8 3, 8 -

+ Addition/

- Subtraction/ ( , 8

* Multiplication/

/ Division/ -

, 8 , - , 8 ( ( 3, , 8


se of T. (Brackets) , 8 ,2 (/) & (/) &3 3, 8, 8@ , 8 , 8 - , 8 ( ()
&3 ( ( , 834 ( , , 8 ( , 8 ,2 ( , 8 ( ( , 3, 8 ) 3 ( 3, , 8
, 4 ( ( ( , , 8 ( , 8 4, 8 4 ( , 84 , 84 , 8 , 8 ( 4 ( , 8 4 (
( , , 8@, :) 4 ( ( , 8 - , 8 :) , 8 , 8 4 ( ( , 8 :

------


4 ( ( - ( m , , , 8 2 4, 8 4 ( ( , 84 , 8 , 8 :


-----
)

------------

4 ( - , 8 ( , 84 , 8 , 8 :
( , 8 , 8 :) 4 , 8 ( , 84 3, 8 ''100 / 20''

( , 8 ( ( , 8 , 3 , ( ( , 834 ( - 4 4 ( , 8 - , 8 , 8

. 8 (Brackets) &3 '', 8 , 8 , 8 ( 3 4 '' (Order of


Operations)

( ( - - ( ( - ( , 8 , 8 ( 8 v , 8 3 '', 8 , 8 , 8


( 3 4 '' , 8 , 8 , 8 , 8 &3 , 8 3 , 8 , 8 (, 8, 8 ( , 8 , 8 ( 4 ( (
( , 8 , 8 ) , 8 @ , 8 , 8 , 8 , 8 , 8@ ( 4 ( , 8 , 8 ( , ( , 8 ,
, - ) 4 # - , 8 , 8 , 3 , 8 , 8 , 8 -- , 8 , -
( , 8 , 8 , 8 , 8 , 8 , 84 3 ( , , 8 , 8 , 8 (+) 3 4, 8 ( 3 4 3, 8:

>>> print(5 + 30 + 20)


55

( , 8 , 8 ( , 8 , 8 , 8 , 8 4, 8 , 8 , 8 ( , , 3, 8 ( , 8 , 84
, 8 :

>>> print(5 + 30 - 20)


15

( ( , 8 , 8 , 8 , 84 , 8 , , 8 ( , 8 , 8 , 8 , 8@ , 8 , 8 , 8
( , 8 , 8, , 8 , 8 ( ( ( 4 3, 8 ( , 84 3, 8 , ( , 8 , 8 4
, , 8 , 8 4 3 (, 8 , 8 , 84 3, 8 ( 3 4 , 8 [ , 8 , 8, 8 )
2 , 8 , 3, 8:

>>> print(5 + 30 * 20)


605

( , 8 , 8 ( ( 8 &3 ( 4 3, 8 ( 3, 8 ? ( , 8 , 8 , 8


se of T. (Brackets)
se of T. (Brackets) (
:


>>> print((5 + 30) * 20)
700

se of T. (Brackets)


se of T. (Brackets) , 8 , 8 2 & ? 8 ( 3 4 ( , 8@ 8 , 8 , 8 4 , 8
, 8 , , 8 , 8 :) , 8 , 8 , 8 , 8 , 8 ( , 8 , 84 , 8 ( , , , 8
, 8 4 , 8 v ( , 8 , 8 ( ( 8
, 8 4, 8 4 ( 3, , 8 ( ( ( , 8 , 8 , 8 8 -4 8 &3 3, 8, 8@ :

>>> print(((5 + 30) * 20) / 10)


70

, 8, 8, , 8 , 8 , , 8, 8 -4, 8 8 , 8 , 8 , , 8 8, 8 8, 8 , 8 , 8 8
:) :) , 8 , 8 , 8 , 8 4 , 8 , 8 , 84 , 8 ( '' , , 8
, 8 4 , , 8 , 8
se of T. (Brackets) , 8 ( , 8 - '' 8 @
se of T. (Brackets)
se of T. (Brackets) ( @ ( - 3, 8, :

>>> 5 + 30 * 20 / 10
65

, 8, 8 , 8 , , 8 , 84 3, 8 , 4, 8


se of T. (Brackets)
se of T. (Brackets) , 8 - , 84 3, 8 ( , 8 , , 8

se of T. (Brackets)


se of T. (Brackets) , 8 , , 8 , 8 #
se of T. (Brackets)
se of T. (Brackets) , 8 , 8

, 8 , 84 3, 8 , 4 , 8 2 8 &3 3, 8 44 - , 8 , ,


( , 8 , 8 , 8 3, 8

. - ( , 8 , 8 , 84 ( [ ( @

( , 8 &4 ( 3, 8F - ( , 8 (variable) - ( , 8 &3 3 ( @


, , 8 [ , 8 2 , 84 - ( , 8 ( 3, , 8 , & , , & 4 (
:) , 8 ( 2 , 84 , 8 , 8

( - ( , 8 , 8 ( , ( 3, , 8 ( ( 4, 8 -4, 8 ( ( W :) :) ( @ , 84


, 8 ( , - , 8 - ( , 8 ( 3, , 8 ( @ ( 2 , 84 , 8 ( ( , , 8
( ( - , 8@ ( , ( , 8

4, 8 , 8 , 8 - ( , 8, 8 & , 8 (


( @, 8 - ( , 8 ( 3, , 8 ( , 84 4 ( ( , 84 3 - ( , 8, 8 , 8 ( , (
(=) ( , 84 3 - ( , 8 X4 ( , 8 , 8 , 8 , 8 ( , 84 3 - ( , 8 ( , 8 ( , 84
( @, ( 3 ( , 8 ( ( , 8 3, 8 :

>>> ektara = 100

, ( - ( , 8 X4 ( , 8 ( @ ( , 8 ( @ ' ektara , 8 ( , 8 ( @ ( ( , &


, 8 , 84 , 8 428, 84 , 8 , 8 , 8 ( , 84 , 8 , 8 4 (
, 8 :) , 8 , 8 , 8 3 ( , 8 428, 84 ( Y, 8 , 8, 84 4, 8 , 8, , 8
'print'
se of T. (Brackets, ( , 8 8 , 8 - ( , 8, 8 ( , 8 ( , 8 , 8,2 enter 8 , 8, 8 , 8
- ( , 8, 8 ( , 8, :

>>> ektara = 100


>>> print(ektara)
100

( - ( , 8, 8 , 8 ( 42 ( 4, 8 , 8


se of T. (Brackets)
se of T. (Brackets) , 8 , , 8 ( ( 424 , 8 , :

>>> ektara = 200


>>> print(ektara)
200

, , 8 , 8 ( ( F ektara - ( , 8 ( ( , 8 2 , 8 ( v48 , 8


, 84 ( F ektara ( ( , 8 2 , 8@ 4 , 8
se of T. (Brackets)
se of T. (Brackets) ( 3, 8, , 8 , 8 ( 42 ( , 8F - , 8
- ( , 8 ( 3, , 8 ( , 8 , 8 ( , 8 2 , 84 , 8 ( , :

>>> ektara = 200


>>> ankur = ektara
>>> print(ankur)
200

, 8, 8 , 8, , 84 , 8 , ( ankur ( W , 8 ( @ ektara- ( , 8 2 , 8 , ektara
( , 8 2 , 8 ( , & , 8 , ektara ( 3, 8, , 8 ( ,
, 8 428, 84 ektara , 8 4 , 8 - ( , 8, 8 ( 2 , 8 , q 8 3, 84 3, 8
, 8 - ( , 8, 8 ( 3, , 8 ektara &3 , 8 ( @ ( ektara ( , ,
&3 3

, 8 , , 8 , 8 ( @ , ( , 8 2 , ( ( W , 8


&3 3 ( ( - ( , 8 , 8 , 8 :) &3 3 4 - ( , 8, 8
( 2 ( , 8#2 (

( , 8 ( 3 ( , 8 ( ( , , , 8 2 , 8 r 3, 8 , 8 , 8 , 8 , 4 ( , 8 , 8,
, 8 , 8 , 8 ektara = 200 2 ( - ( , 8 ( 2 , 8 ektara ( , 8 2 , 8
( ( , 8 2 , 8 4 ( 4 , 8 , , 8 ( 3 , 84 3, 8 , 8 ( 3 , 8
, 3 -# ( , 8, 8 3, 8 , , 3 -# ( , 8 4 ( ( & , 8 , 8 3, 8
, 8 , 8, , 8, 84 q ( , 8 , 8 #, 8 , 8 , 8 , , 8 4 (
, (
se of T. (Brackets) , 8 4 ( , , 8 , , 8 , , 8 4 ( 4 ( , 8 , 84 , 8 , 8 , 8 ( , 8F
3, 8 ( @ ?

, 8 3 ( , 8 , 84 , 8 , 8


( ( @ , 8 , 8 ( @ 'ektara=200' ( -, 8 ( @ v ( ? 4 3, 8 @
, 8, 8 ( 8- , 8 , 8 , 84 , 8 , 8 4 , 4?

( ( ( - ( , 8, 8 - , 8 number_of_students, 2 ( ( ( :

>>> number_of_students = 200

- , 8 ( , 84 , 8 ( , - ( , 8, 8 , , &


se of T. (Brackets, , 8 (-) , 3 , 8 3, 84 , 8 , 8
, 8 , 84 - ( , 8, 8 , & ( , 8 , 8 4 ( ( @ , 8, 8 (
se of T. (Brackets) , 8 , 8,
4, 8 - ( , 8, 8 number of students v ( 4 4 ( , 84 , 8 , 8 4 4 ( , 8 , 84
, 8 , 8:

>>> print(number_of_students)
200

4 ( , 84 , 8 , 8 , 8 @ , 8 , & 3, 8F 4, 8 - ( , 8, 8 , , 23
3, 84 , 8 , 8 ( , 8 3, 84 , 8 , 8 ('a'), & &3 , 8
, 4 ( ( 4 ( ( , 84 4, 8 , 8 ( :) , , 3
( ( , 84 , 8 , 8 ( -2 , 8 4 ( , 8 428, 84 8- , 8 ( , 8 &3 , 84 4 ( 8- , 8
( , 8@ 4 , 8

- ( , 8, 8 , , 8 , 84 3, 8 , ( q ( , 8 - ( , 8 , , , 8 8


- ( , 8 3, 84 , 8 , 8

. - ( , 8 , 8 &3

( 8- , 8 ( - ( , 8 X4 ( , 84 3 ( ( 8- , 8 &3 , 8 ? , 8 ( ,


, 8 ( , 8 , 8@? , 8 3, 8 ( @ , 4 ( ( 4 , 8, ( (
se of T. (Brackets) , 8 :) , 8 H (
( 3, 8, , 8 , 8 , 8, 4 3 , 4 3, 8 @ , 8 4 3 , 84 4
, 8, 4 3, 8 , 8 ( 3, 8:

>>>((200+300) - 250)* 12
3000

( ( 4 ( , 8 - ( , 8 ( 3, , 8 ( 4, 8 , 8 ( , 84 3, 8 :

>>> tiffin = 200


>>> stipend = 300
>>> spending = 250

, 8 ( 4 ( - ( , 8 X4 ( , 8 ( @ 4 , 8 ( , 8 ( @ 'tiffin', 'stipend' and 'spending'
, 8 ( , 8 4 , 8 ( , 84 , 8 ( :


>>> print((tiffin + stipend - spending) * 12)
3000

, - ( , 8 X4 ( ( 4 ( ( @ , 84 , 8 , 8 , 4 ( ( , 8,


( (
se of T. (Brackets) , 8 :) 50 ( , 8 4, 8 - ( , 8, 8 200 [, 8 250 ( , 84 3, 8 :)
, 8-& , 8 8 (up-arrow key ) , 8, 84 3, 8 4 , 8 2 tiffin=200 , 8, 200 , 8@ 250 ( , 8

se of T. (Brackets , 8, 8
se of T. (Brackets)
se of T. (Brackets) , 8 , 8 , :

>>> tiffin = 250


>>> print((tiffin + stipend - spending) * 12)
3600

4 , ( , 8 3, 8, 8@ 3600 4 ( ( , 8 ( , 8 :) :) - ( , 8 , 8 ( 42 , 8
, 84 , 8 , 8 ,
se of T. (Brackets)
se of T. (Brackets) , 8 ( 42 3, 8 , 8F 4 ( ( 4 ( , & 50 ( , 8 , 4 3, 8
4 , ( 3, 8:

>>> spending = 300


>>> print((tiffin + stipend - spending) * 12)
2400

2 @ , 8 4 3 , 84 , 8 2400 - , 8 - ( , 8, 8 ( , &3


- ( , 8, 8 , ( 4& , 8 &3 ( ( 4, 8 &3 , 8
, 84 , 8 ( - ( , 8 &3 3 ( @ , , 8

- ( , 8 , 8 ( , 8- , 3 , ( 3, , 8 , 8 , 84 , 8 , 8 !

. , 8 ( a

4 , 8 ( , 8 , 8@ ( , 84 , 8 - ( , 8 , , , 8 2 , 8 ( @ ( , - ( , 8


( 3, , 8 , & ( 2 , 8 ( , 84 , 8 ( ( , 8 ( - , 8
, 8 ( a ( 3, , 8 ( , 8 , 8 ( ( ( a F @ , 8 ( @

, 8 ( @ , , 4 ( ( a

, 8, , 8 , 84 3, 8 , ( ( a 3, 8F , 8 ( , ( , 8 , ( r , , 8


( 2 , 8 , 8 , , , & ( ( , 8 ( 2 , 8
4 ( ( a 3, 84 , 8 , 8 4 , ( W ( ( a 3, 84 , 8 , 8 4 , 8 (
, 8 , 8@ & , 8 ( , 8 ( ( , 8 ( @ , , 8 ( ( a &3
, 8 ( @ , ( @ : Hello World


, 8 , 8 ( , 8 ( ( ('') -4 , 8 ( a X4 ( , 84 3 , 8 , 8#, 82 ektara
- ( , 8, 8 ( ( a , 8 , ( , 8 3 ( :

>>> ektara = "this is a string"

, 3, 8 , 84 , 8 , 8 ektara - ( , 8, 8 -4 ( , 8 ( @, :) , 8 , 84 3, 8:

>>> print(ektara)
this is a string

( ( &3 , 8 ( ( a X4 ( , 84 3, :

>>> ektara = this is yet another string


>>> print(ektara)
this is yet another string

( ( ( 3, , 8 ( ( (Single quote ' ') ( v ( ( (Double quote )


-4
se of T. (Brackets , 8, 8 ( ( , 8 ( 4, 8 ( , 8 , 2 ( , 8 , 8

se of T. (Brackets , 8 ( , 8 ( , 8 ( 3 ( , 8 ( ( , 84 , 8 ( :

>>> ektara = "this is two


File "<stdin>", line 1
ektara = "this is two
^
SyntaxError: EOL while scanning string literal

( ( ( , 8 , 8 428, 84 , 8 )

( ( , 84 ( 4 ( &3 , 84 3, 8 :

>>> ektara = this is two


... lines of text in a single string

print
se of T. (Brackets, ( , 8 , 84 , 8 ( ( 4 ( , 8 :

>>> print(ektara)
this is two
lines of text in a single string

, 4 ( ( ( 4 ( &3 , 8 , 8 4, 8 , 8


se of T. (Brackets , 8 ( 4 ( ,
(...) - , 8 4
se of T. (Brackets ( , 8 44 ( 4 ( , , , 8 4 ( , 84 , 8 , 8 ,, 8 , 8
4 ( ( @ ( , 84 , 8 , 8


. ( a , 8 ( @ q

F 4 , 8 ( ( , , 84 , 10 * 5 ( ) 4 3, 8? Y ( W , 8 , 8@ ,


3, 8 50 4 ( , 84 , 8 , 8 3, 8 ? 4 ( , 3, 8 , 84 , 8 , 8
F ( ( 10 * 'a' ( a ) ( 3, 8? 4 4 ( 3, 84 , 8 ( ( 238
( , 8 , 8 , 84 , 8@ , 4 ( , 8 , 8, , 8 >>> print(10 * a)
se of T. (Brackets , 8
, 8 ( , 8
se of T. (Brackets)
se of T. (Brackets) , 8:

>>> print(10 * 'a')


aaaaaaaaaa

( ( , 8 , 8 3, 8 , ( , 8 3 ( :

>>> print(20 * 'abcd')


abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdab
cdabcdabcdabcd

( a :) , 8 ( q 3, 8 , ( a , 8 , 8 [ , 8 (embed) , 8 ( %s


&3 , 8 ( 2 ( 3, , 8 &4 3 %s ( a &3 , 8 , 8 428, 84
, 8 ( , 84 , 8 ( ( 3 ( , 8 ( ( , 8 ( , 8 3, 8 :

>>> mytext = I am %s years old


>>> print(mytext % 12)
I am 12 years old

, 8 , 8 ( ( , 3 (placeholder-%s) (placeholder-%s) , 8 ( - ( , 8


mytext X4 ( 3, 8, 8@ , 8 &4 %s ( , , 8 4, 2 , 8
, 8, , 8 , 8 ( @ ( , 8 ( 4[ , 8 , 8 , 8 428 , 8 print(mytext)
( , 4 % ( ( &3 , 8 , 8 % , 8 ( , 842 12 &3
, 84 - , 8 % , 8 ( , 842 :) :) ( @ &3 , 84 , 8 ( ( , 8 3 , 8 :

>>> mytext = Hello %s, how are you today?


>>> name1 = Lipi
>>> name2 = Rana
>>> print(mytext % name1)
Hello Lipi, how are you today?

>>> print(mytext % name2)


Hello Rana, how are you today?

, 8, 8 3 , 8 , 84 , 8 , , 8 ( 4 ( - ( , 8 (mytext, name1 and name2) X4 (
3, 8, 8@- ( , 84 % 2 , 8 &3 , 8 ( @ mytext - ( , 8 ( print , 84 , 8 (
, 8 % , 8 ( , 842 name1 name2 &3 , 84 , 8 ( @ 4 ( ( ,


3 (placeholder-%s) &3 , 84 , 8 , 8 , ( , 8 3 ( :

>>> mytext = Hello %s and %s, how are you today?


>>> print(mytext % (name1, name2))
Hello Lipi and Rana, how are you today?

( 2 &3 3, 8 4 2 , 8 8 , 8 & , 84 3, 8 2 ( 2 , 8


4 , ( W ( 3, 8 - (name1, name2) , 8 , 8 2 , 8 4H48 8
, 8 & , 8 4 4 , 8 , 8 (tuple) 3 ( , 8 ( , 8 , 84 , , , 8 2 , 8, 8
, 8

. r ( 4 ( X4 (

4 ( ( 4 ( X4 ( , 8 @, , , ( ,, , , :) ( ( , 8 ( , 8#2


4 ( ( , 8 :) , 8 r ( , 8 , 8 ( - ( , 8, 8 ( a ( 3, , 8 ,
, 84 4, 8 4 3, 8:

>>> shopping_list = eggs, milk, fish, banana, potato, meat


>>> print(shopping_list)
eggs, milk, fish, banana, potato, meat

, 8 , 8 :) - , 8 ( ( 'list' X4 ( , 84 , 8 ( , , 8 ( ( , 8 &3 , 8 , ( , 8
3 ( :

>>> shopping_list = [ 'eggs', 'milk', 'fish', 'banana', 'potato',


'meat' ]
>>> print(shopping_list)
[ 'eggs', 'milk', 'fish', 'banana', 'potato', 'meat' ]

, 8 , 8 , 8 ( @ ( , 84 3, 8, 8@ , ( 4 :) , 8 8 ( , 8


, 3, 8 4H48 , 8 ( ( , 8 index position 3) print , 84 , 8 ( , [ ] 8 -4 , 8
:

>>> print(shopping_list[2])
fish

( 3 0 , 8 ( , 8 , , 8 , 8 , 8 [ 0, - , 8 ( v48 ( , 8 ( 1,


4H48 ( [ 2 ( , , 84 , 8 , 8 , 4, 8 ( , 8 ,
4 ( 4 , , 8 ( , Y ( ( , 8 W, 84 ( , 8 ( , Y ( , 8 , 84 , 8 4 ( 3, 84 , 8
0 , 8 4, 8 4 ( , 84 , 8 ( , 8
se of T. (Brackets) , 8 , 4 , 8 ( , 8
( , 8 , 8 ( X4 ( , 3, 8 0 , 8
, 8 3 , 8 , ( , 8 4H48 [ , 8 , 8 [ , 8 , , 8 , 84
, 8 , 8 , [ ] 8 -4, 8 ( &3 , 8 , :


>>> print(shopping_list[2:5])
['fish', 'banana', 'potato' ]

, 8,, 8 , 8 [ , 8 ( ( , 8, 4 ( , 84 ( , 8 [2:5] - , 8 ( , 8
, 84 , 8 ( 4 ( &3 , 8 , , 8 , 8 H ( 4 - , 8 , :) , 8
, & , , :

>>> mylist = [ 1, 2, 5, 10, 20 ]

( a 3, 8 -

>>> mylist = [ a, bbb, ccccccc, ddddddddd ]

( a ( ( 3, 8 :

>>> mylist = [1, 2, a, bbb]


>>> print(mylist)
[1, 2, a, bbb]

( ( , 8 ( 3, 8 -

>>> list1 = [ a, b, c ]
>>> list2 = [ 1, 2, 3 ]
>>> mylist = [ list1, list2 ]
>>> print(mylist)
[[a, b, c], [1, 2, 3]]

, 8, 8 3 , 8 ( - ( , 8 list1 X4 ( 3, 8, 8@ ( 4 ( ( , 8, list2 X4 ( 3, 8, 8@ ( 4 (
, & ( , 8 mylist X4 ( 3, 8, 8@ list1 list2 ( , 8 ( ( ( , ( , 8 - ( , 8 X4 (
( 4, 8 4 , 8 , ( ( 3, 4 ( 4 ( X4 ( ( 4, 8 4 4, 8 4 ( 3
, , 8 4 X4 ( , 84 , 8 , 8, @ - , 8 4 ( X4 ( , 8 , 8 , 8 , 3, 8 ,
, 8 , 3, 8 , , 84 , 8 (

4 ( , 8 , 8 8

, 8 , 8 ( 4[ , 8

, 8 , 8 , 3, 8 4 ( , 8 , 8 ( 4[ , 8 - , 8 - ( , 8, 8 ( 2
( ( W , - , 8 4 ( , 8 , 8 , 8 , 8 ( 42 , 4H48 [ , 8
banana , 8 ( 42 , 8 chili , 84 , 8 ( :

>>> shopping_list[3] = 'chili'


>>> print(shopping_list)
[ 'eggs', 'milk', 'fish', 'chili', 'potato', 'meat' ]

( , 8 ...

, 8 , 8 4 ( 'append ' , 8 ( 4 &3 , 8 ( , 8 , 84 , 8 (
'append' , 8 ( 4 , 8 , 8 , 8 ( , 8 2 4 ( ( @ , 84 ( F , 8 ( 4
, , , 8 2 , 8, 8 , 8 ( , 8 , 8 , 8 4 ( 8- , 8
, 8 ( 4 &3 , 8 ( 4 , 8 , 84 , 8 ( , ( , 8 3 ( :

>>> shopping_list.append(mango)
>>> print(shopping_list)

[ 'eggs', 'milk', 'fish', 'chili', 'potato', 'meat', 'mango ]


, , 8#, 82 4 ( , 8 ( 42 , 8 4 , 8 , 8@, 8J ( , 8& '' 4 (
3, 8, 8@

... 4 ( , 8 ( @ , 8@


se of T. (Brackets)

'del' (delete , ( , 8) &3 , 8 , 3, 8 4 ( , 8 @, 84 , 8 (
3 , 8 4 ( 4H48 [ , 8 , 8 ( (chili) @, 84 , 8 , 84 3, 8:

>>> del shopping_list[3]


>>> print(shopping_list)
[ 'eggs', 'milk', 'fish', 'potato', 'meat', 'mango ]

4 , 8 , 8 ( , 8 ( , 84 4 ( 3 # :) [ , 8 , 4 4 2 [ , 8 , 8 (


4 ( [ 3, 8 4H48

( 4 ( ( , 8 - , 8

4 ( , 8 , 8 , 8 4 ( , 8 , 84 , 8 ( , ( ( , &


, 84 4, 8:

>>> list1 = [ 1, 2, 3 ]
>>> list2 = [ 4, 5, 6 ]
>>> print(list1 + list2)
[1, 2, 3, 4, 5, 6]

( 4 ( , 8 4
se of T. (Brackets)
se of T. (Brackets) :) ( - ( , 8, 8 , , 84 , 8 ( , :

>>> list1 = [ 1, 2, 3 ]
>>> list2 = [ 4, 5, 6 ]


>>> list3 = list1 + list2
>>> print(list3)
[1, 2, 3, 4, 5, 6]

- , 8 4 ( , , 8 ( a , 84 , 8 ( :

>>> list1 = [ 1, 2 ]
>>> print(list1 * 5)
[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]

, 8, 8 3 , 8 4 ( , 8 ( , 8 3, 8, 8@ , :)- , 8 , 84 , 8 , 8 , 4 (
, 8 H ( 3, 8, 8@ ( 4 ( ( , 8 , 8 4 - (/) ( , 8 (-)
2 , 8 , 8 4 , 8 , 8, ( , 8, ( , 8 3 , 8 :

>>> list1 / 20
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for /: list and int

>>> list1 - 20
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: type and int

, , 8 , 8 , 8 ( 42 , 8

. , 8 4 (

, 8 , 8 4 ( , 84 , ( 4 8 [ ] , 3 , 8 & &3 3 4 ( , 8


8 () v ( - (' ') 4 ( [ ] 8 v , 8 3 :
>>> t = (1, 2, 3)
>>> print(t[1])
2

( , 8 2 & 3, 8 4 ( , 8 , 8 , 8 ( 42 ( , 8 X4 ( 3, 8


4 , 8 , 8 , 8 ( 42 ( , 8 ( 42 , 84 4, 8 , 8 , 8, ( 42
, 8, :

>>> t[0] = 4
Traceback (most recent call last):
File "<stdin>", line 1, in ?


TypeError: tuple object does not support item assignment

, 8 , , 8, 8 -4, 8 - ( , 8 , 8 ( 42 , 8 , ( , 8 3 ( :

>>> myvar = (1, 2, 3)


>>> myvar = [ a, list, of, strings ]

, , 8 ( - ( , 8 myvar X4 ( , 8 ( @ ( 4 ( , 8 , 8 ( , 8 2 , 8 , 8
myvar , 8 ( 42 , 8 ( @ , 8 ( ( a 4 ( , 8 ( , 8 2 , 8 ( , 8 ( ( , 84

se of T. (Brackets) , 8 ( 4 ( ( - , 8 ( , 4 , ( , 8@ ( 4 , 8 , 8, 8 (


, 8 , 8@ 4 ( , 8 ( @ , 8 , 8 4 ( , 8 (
se of T. (Brackets) , 8 ( , 8 , 8 4 (
& ( , 8
se of T. (Brackets) , 8 4 ( ( ( Y, 8 , 8, 8 , 8 ( @ , , 8 (
, 8 , 8 , 8 2 & ( , 84 , 8 ( @ , 8@ ( 4 4 , 8@ (
, 8 ( ( , , 84 , 8 , 8 , , 8 3, 8 4 4 ( -4, 8
( @ , 8 ( 42 , 84 , 8 , 8@ ( 4 ( 4 , 8- , 8 ( W, 8 ( 4 @ , 8 , 84 , 8 , 8
, 8 4 ( 4 ( , 8 , 8 , 84 , 8 , 8


. , 8, ( , 8 (

& , 8 , 8 ( @ 8- , 8 , 8 , 8, &3 , 8 ( ( 4 , 8 , 8 ,


, 8 , 8 ( @ 8- , 8 8 &3 , 8 , 8 , 8
se of T. (Brackets)
se of T. (Brackets) , 8 ( 42 , 8- , 8 8 &3
, 8 , 8 , 8 , 8 , 8 ( @ , 8 ( @ , 8 8- , 8 ( 2 ( 4 , 8 , 8 428, 84
&3 , - ( , 8, 8 &3 , 8- , 8 , 8 , ( , 84 , 8 , 8 ( a &4 3, 8- , 8
4 ( , 8 &3 , 8 ( 4 ( ( , 8 ( , 8 ( @ , 8

8 8
4 ( ( 4 ( X4 ( , 8 toys 4 ( , #, 83 (
4 ( X4 ( , 8 foods ( 4 ( , 4 favourites,
4 4 ( (
se of T. (Brackets)
se of T. (Brackets) (print)

8 8
4 ( ( 4 ( , 8 ( , 8 , 8 ( & , 8 ( ( ( r , 8 4 3, 8 4 4, 8
( ( r , 8 , 8 , 8

( ( ..: 4 ( ( , 8 , 8, &3 , 8 ( , 8 , 8 , 84 , 8 , 8)

8 8
4 , 8 &3 , 8 ( - ( , 8 X4 ( ( ( a X4 (
, 84 4 , 84 ( , 3 (placeholder-%s) &3


4H48 &

( @ :) :) 8 ( 4 8

( @ , 8 2 @ ( 4 , ( 2 n 4 ( , 8 @? 4 ( , 8 ( @


, 8 , 8 , 8 , 8 ( @, 8 , , 8 , 8 ( @, 8 , 8 ( , 8, 8@ , 8 ( @ 3? (
2 n 4 , ? Y, 4 , 8 ( , 84 , 8 ( @ , , 8 , 8, H, 8 4& 8 ( 4, 84
, 8
se of T. (Brackets) , 8 ( , 8, 8W , 8 , 8 4 4 , [ 3 , 8 , 8 , 8 ( , ( @ 3
, 8 , 8 48 ( ( , , 8 , 8 2 8 ( 4, 84 , 8 ( , 8 (
3 &, 8

, , 8 , , 8 ( , 84 , 8 , 8 , 8 ( @ ( , , 8 , 8 2 , ( ( , 8 ,


& , 8 :) , 8 ( @, 8 , , 8 ( , 8 , 8, 8 3, 84 :) 8 , 8@ 4 , 8
, 8
se of T. (Brackets) , ( , 8 4, 8 , , 8 3, 84 , 8 , 8 ( ( 4 4 ( 4 8
, 8 , 84 , 8 , 8@ ? ( , 8 , 8 4 3, 8 , 8 , 84 , 8 , 8 , 834 , 8 ( 4
( @ (turtles) ( , 8 , ( ( @ 4 , , 8 , 8 2 3 , 8@
, , , 8 ( , 8 Y , 84 Y , 84 , 8F

, 8 , 8 , 8, , 8 , 8 ( , ( ( - ( @ ( - ( , 8 ( @


( @ , 8 , 8
se of T. (Brackets :) , 8 &4 34 42 , 8 , 8 ( , , 8 - , 8 ,
, 84 , 8 , 8 , , , 8 , , 8 , , 8 ( - ,
se of T. (Brackets) 3, 8 ( @, 8 , 8, 84 , - , 8 , 84

, 8 3, ( ( , 8 , , 8 , , 8 , , ( 3 , 8# 3 --- ( @


( @ , 8 & , 8 3, 84 , 8 4

, 8 , 8 2 (turtle) ( ( , ( ( , ( , ( , 8 , 8, 8 , 8 , , 8 44 , 8

( : .: ( 48 2 ( 4, 8


( , 3, 8F ( , , 8 ( , 8 &4 3 ( ( ( , ) ( @ , 8 ( ( -
4, ( , 8 ' ( @ , 8 4 , , 8 , 8 , 8, 8@ , 8 ( , 8 4 2 ( , &3 , 8 &, 8
4 ( , 84 , 8 , 8 ( , , 8 , 8 2 8- , 8 @ ( Y , 84 3

4 3, 8 8- , 8 ( , 8 3, 8F , 8 , 8 2


&3 , 84 , :) ( , , 8, 8 2 , 84 3, 8:

>>> import turtle

, 8 ( & - , @ ( ( Y :) & - , ( 4 , Y ( , 8 @ (


Y :) ( &3 , 8 , 8 :

>>> t = turtle.Pen()

, 8,, 2 ( ,, 8 ( ( , 8


se of T. (Brackets) (Pen) ,, 8 ( @, ( m- , 8 ( & - ,
X4 ( , 8 , 8 @ ( Y
se of T. (Brackets) 3, 8F &3 , 8 & , 8 , (

se of T. (Brackets) ( , 8 , 8 428, 84 ( , 8 ) , 8


2 8 --- , 8, , 8 2, 8 , 8 Pen
se of T. (Brackets) , 8
&, 8
se of T. (Brackets) 4 , 8, , 8@ --- , 8 ( 3, 8, , 8 ( 2
, 8 ( @ 't' -& ( , 8 (
se of T. (Brackets)
se of T. (Brackets) , 8 , , 8 , 8, 8
& - , 't' , 8 , 8 ( ( 4 3, 8F) 4 , (
, 8 , 8, , 8 ( , 8, 4 ( . 4 (
( ( & - , ) , 84 , 8 , 8

Y, , 8 2 , 8 @ 48 ( 3 , ( 4& , ( 4& (


( @ ( , ( , 84 , 8 ( @, 8 4

4 ( @ ( , 8 ( , 8 2 ( , 84 , 8 , ,

se of T. (Brackets) ( &3 , 8 ( 4 , 8 X4 (


, 8 (turtle.Pen)--- , 834 , 8 ( 3, 8, , 8
-& ( , 8 't' ( 2 , 8 ( @ , ( , 8 2
:) 't' &3 4 3, 8 ( , 8 2 ( , ( .: ( @, 8 Y (
forward '
se of T. (Brackets) ,2' ( , 8 2 ( ( @ [ , 8
, 4 , 8 , , 8 , , 8 , 84 , 8 ( ( @ ( , 8 ( @, 8 , (
, 8 44 , 8 ( ( , 8 ( @)

( @ ( , , 8 ( , 8 ( , 8, 8 , , 8 , 84 ( , 8, 8 ( , 8, 8 ( , 8 , 8
):

>>> t.forward(50)

, ( ( , 8 4 ( . 4 ( @ , 84 , 8 , 8

( ( @, 8 - , 84 , 4 3, 8 , ( @ ( , , 8 ( , 8 ( , 8 , 8, 8 ( , 8, 8@


( , 8 , 84 , 8 ( , 4 3, 8 , ( @ ( ( , 8, 8 , , 8 , 8@

4 3, 8 , ( , 8, 8 8?

( ( , 8, 8 3, 8F , 8 2 , 8 ( , ( , , 8 , 8 2 ( , 8 4 ( , 8 4 , 8 4 , ( @
@ @ ,, 8 (2 H ( 4 ) , ( r 4 ( , , 8 , 8, 8 (Playstation) , 8
(Xbox) -4 (Wii) ( &3 4 , ( @ X4 ( 3, 8, 8@ ( ( -
, 8 , 8 , 8 ,, 8 , ( r v 4 & (
se of T. (Brackets) , &3 , 8 ( ( , , 8 , 8 2
4 3, 8 , & ,, 8 , ( r , 84 , 3, 8 ( , 8 & - , ( , 8 , 8 ( 4 3, 8
, 48 ( 2 ( @ ( , ( Y, 8 ( @ 4 , , 8 , 8 ( ,, 8 , ( r ,
( . , 84 , 8 ( F

( , 8, 8 , ( , 8 , 8 428 & , 8 , 84 , 8 ( @, 8
, ( , 8 , 84:

( .: 48 ( , 8 , 8 3, 8, 8@

( .: ( ( - , #3 (divisions)
>>> t.left(90)

, ( @ , 8 ''4 ( 4 [ , 8 ( , 8 ( , (8 , 8 '' 4 ( 34 , 8


( , (8 , , , 8 2 , 8 ( , ( , , 8, 8 , 3 - , 8 , , , 8 2 ( , 84 , 8 , 8 , ( 4 ( ( ( , 8
4 - , 8 , ( W ( . 4


( , , 8 , 8 2 & 3, 8F, ( - , 8 , 8 ( , 842 ( ( - , ( 4 ( ( , 8 ), , 84
, 8, 8@ ( - 4 4 ( ( ( , 8 4 ( , 8 ( - , 4 , 8 , 8 , 8
, 4 , 8 , ( ( - , 4 3, 8 , 8 , 8 ( , , 8 , 8 , 8 ;

( : .: ( , (8

, 8 , 8 , 8, 8 , , 8 4 , 4 ( . 4 ( , (8 - , 8 , 84 , 8 , 8


4 , t.left(90)
se of T. (Brackets)
se of T. (Brackets) 3, 8F 48 ( , 8, 8 ( , 8 , 8 , 8, ( . 4
, 8,
se of T. (Brackets, , 8 &3 ( :

>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)

, 8 ( @ ( ( 2, 8 , 8 , 8@ ( , 8 , 8 , 8@ 2 - , 8 , , 8 ( @


( ( . )

clear &3 , 8 & - , 8, @ ( , 8@


se of T. (Brackets) , 84 , 8 :


.: ( , 8 , 8 ( @, 8 [

>>> t.clear()

:) :) ( ,
se of T. (Brackets) ( @, 8 , 3 , 8 & 4 &3 , 84 , 8 : reset, , 8, 8
& - , 8, , @ ( , 8@
se of T. (Brackets) , 8 ( ( @ ( , 8 ( [ , 8 ( , 8 , 8 ; backward, ( @ ( , 8
, 8@, 8 ( , 8 , 84 , 3 & , 8 ; right, ( @, 8 , ( , 8 ; up, ( @, 8
, , 8 , , 8 @ ( Y , 84 ( , 8 2 ( :)- , 8 , 8 , ( @, 8 ( 4, 8 ); down,
( @, 8 , 8 @ ( Y ( , 8 2 , 8 - , 8 :)
se of T. (Brackets) &3 , 8 3, 8, 8@ 4

( .: 2, 8


- , 8
se of T. (Brackets) , 8 &3 , 84 , 8 , 8:

. 4 ( , 8 r :

>>> t.reset()
>>> t.backward(100)
>>> t.right(90)
>>> t.up()
>>> t.down()

, 8, 8 turtle ( ,, 8 (


se of T. (Brackets) , 8 ,

. 4 r

& , 8 , 8 ( @ 8- , 8 ( ( @ v Y , 84 3 , , ( , 8 , 8 &, 8


, 8 ( @ ( @ :) ( , (8 &3 , 8 , , 8 ( , 8 & ( ( , 8 - , 8 4

8 8

turtle Pen
se of T. (Brackets) &3 , 8 ( & - , X4 ( ( 4, 8 Y

8 8

turle Pen
se of T. (Brackets) &3 , 8 , 8 ( & - , X4 ( ( ( -# Y


4 2 &

, 8 , 8 , 8 ( 4

, 8 , , 8 ( @ :) ( , 8 , 8 , 8 , 8


( ( , 8 , 8 8 3, 8 4 ( , 8 - ( ? , 84 , 3, 8F? , 8,
( ( @ , 84 4 ( ( ( W , 8 4 , 8
( W ( , 8 , 8 ( , 8 , 8 - ( ( ( , 8
3 , , 8 - , 8 ( , 8 :

4 , 4? ( 4 ( @, 8 ( 3, 4 3, 8 4 ( , 8 !

( ( , 8 , 8 ( ( 4 3, 8 , 8 ( , 84 3, 8, 4 3, 8 :

if age > 20:


print('you are too old!')

, 8 &3 3, 8, 8@ 4 3 ( if-statement ( if-statement 3 if ( , 8 4


, 8 , 8 , 8 42 2 'condition' ( &, 8 , 8 , 8, 8 ( ( 4 ), 4 , 8 , 8
':' , 8 428 3, 84 3, 8 ( , 8 & ( ( 3 ' Y' ', 4&' ( - , 8
( ( - , , 8 ( ) 4 3, 8 , 8 , 8 &
se of T. (Brackets, ( , ( m 3, 8 2 , 8 if-
statement 42 ( ( F 42 ( ( , 8 4 3, 8 ( , 84 , , 8 -4
( @

Condition 3 ( ( ( statement ( 3, 8, , 8 , 8 , 8 'yes' (True) 'no' (False)
( 2 (return) , 8 42 , 8 , 8 :) ( @ 48 /symbol &3 ( 4 , 8 , 84
3, 8 42 , 8 , 8 :) &4 symbol ( operators) , 8 ( ( :

== , /equals
!= , /Not equals
> '' , 8 /Greater than
< '' , 8 @ /Less than
>= '' , 8 , /Greater than or
Equal to
<= '' , 8 @ , /Less than or
Equal to

3 , 8, ( 4 , 3 , 4 3, 8 4 3, 8 4 , 8, condition your_age==10 ( 2


, 8 True (yes), ( ( 4 ( 3, ( ( 2 , 8 False , 8 , 8: ( , 8 , 8 , (
(==) 42 2 condition , ( , ( (=) , 8 , ( 4 3, 8 ( , 8
( (error) , 8


4 , age ( variable 4 , 3, 8, 8@ ( ( - -
, 84 , 8 ( set 3, 8, 8@ condition 3, 8, 8@ ...

age > 10

. , 8 , 8 'True' ( 4 , 3, 4 3, 8 ( ( , 8 'False' ( 4 ,


3 4 3, 8 , 8 , 8 'False' condition ( , 8 8 , 8@ 4 , , 8 (
( @ 3 ( :

>>> age=10
>>> if age>10:
... print('got here')

( 4 ( ( (run) 4 3, 8 , 8 'got here' , 8, ( , 8, , 8 (


se of T. (Brackets 3, 8, 8@ ( ( ,
3, 8 ( 4 , 8 428 3 , 8 :

>>> age=10
>>> if age==10:
... print('got here')

. ( :) ( (Do this... or ELSE) !!!

if-statement , ( 4 , 84 , 8 ( , , 84 , 8 42 , ( 4& 3, 8 ( :) ( @ , 8


3 , 8, ( 4 , 3 4 3, 8 'Hello' ( 24 3, 8, ( ( 4 3 4 3, 8 ( 24 3, 8
'Goodbye' ( :) &3 if-then-else-statement ( :)- , 8 , 8 ( (
Y : ( ( @ , 4& 3, 4 3, 8 ( , ( 4 3, 4 3, 8 :)
( ):

>>> age = 12
>>> if age == 12:
... print('Hello')
... else:
... print('Goodbye')
Hello

, 8, 8 , ( ( 4 , 8 4 3, 8 , 8 'Hello' ( 24 3, 8F 4 ( ,


:) ( @ 4 3, 8 'Goodbye' ( 4
2 3, 8:

>>> age = 8
>>> if age == 12:
... print('Hello')
... else:
... print('Goodbye')
Goodbye


. ( , 8 .. ( , 8 ... , ( , 8 ... :) ( , 8 !!! (Do this... or
do this... or do this... or ELSE!!!)

, 8 if-statement ( , 8 , 84 , 8 ( elif &3 , 8 (elif 3, 8F else-if , (
, 8) 3 , 8, , 8 8 , 84 , 8 ( 4 , ( ?, ?, ? 4& ( :

1. >>> age = 12
2. >>> if age == 10:
3. ... print('You are 10')
4. ... elif age == 11:
5. ... print('you are 11')
6. ... elif age ==12:
7. ... print('You are 12')
8. ... elif age == 13:
9. ... print('You are 13')
10. ... else:
11. ... print('huh?')
12. ...
You are 12

, 8, 8 , 8, ( , 8 8 , 8@ 4 , 2 age variable


, ( ( 4 ( 4 , ( , 8 ( @, 8 , 4 , 8 , , ( , 8 ( , 8 , 8 8
, 8 age 4 , , 8 ( , 8 ( 4
se of T. (Brackets) ( , 8 , 8 , 8 , 8, Y
, 8 ( , 8 , 8@ ( 24 3, 8 'You are 12' (4 ( , 8 @ , 8, ( , 8 , 8, 8@ :
,,, )

. , 8 42 , , 8

4 , 8 4 , 8, 8 8 42 , , 8 , 8 ( , 84 , 8 'and' 'or' &3 , 8 , 8,
, 8 3 ( , 8 42 ( , 8 @ , 8
se of T. (Brackets) ( :

1. >>> if age == 10 or age == 11 or age == 12 or age == 13:


2. print('You are %s' % age)
3. else:
4. print('huh?')

( , 8 , 8 ( 42 , ( 4& 3 ( 2 if age is 10 or age is 11 or age is 12 or age is


13), 4 3, 8 , 8 , 8 , ( 3, 8, :) , 8 , , ( , 8 , 8 , 8
3 ( @ , 8
se of T. (Brackets) , 84 , 8 ( 'and', >= <= ( &3 , 8 &, 8:

1. >>> if age >= 10 and age <=13:


2. print('You are %s' %age)
3. else:
4. print('huh?')


( @ 4 , 84 , 8, 8 @, ( , 8 , 8 42 , ( 4& 3 4 3, 8 , 8 , 8
, 3, 8 , 8 , 8 @

. 8

, 8 , 8 , 8@, -& ( , 8, 8 ( ( 2r , 8 , , 8#2428 & , 8 , 8 ( ( 4
3 : Nothing.
- , 8 -& ( , 8, 8 ( 2 , 8 , - , 8 -& ( , 8, 8 'nothing' ( 2 , 8 ( , 84
, 8 ( , 8 , 8 @ 2 empty , 8 4 None ( 3, 8, , 8 ( 2 ( 4 3 ( :) :) ( ( -
, 8 , 8 , 8 & 3 null) 4 ( , 8 :) :) , 8 4 , , 84 , 8 , 8:

>>> myval = None


>>> print(myval)
None

None &3 , 8 ( -& ( , 8 , 8#, 82 ( @ 4 , 8 ( 2 /reset ,


-& ( , 8 &3 3 , 8#, 82 4 ( 2 , 8 None ( 3, 8, , 8 &3

3 , 8, 4 , 8
se of T. (Brackets) 4 , 8 4 ( , 2 :)
se of T. (Brackets)
se of T. (Brackets, , (3 , 84 , 8 4
4 , 8 3 ( 3, :), 4 ( 4 , 8 4 , 8 ( , 8, 8@ 4 4 ( , 84&
, 8 , 8 :) ( , 8 -& ( , 8 ( 2 , 8 4 , 8 ( 3, 8, , 8 None &3 , 84 , 8
, 8 428, 84
se of T. (Brackets)
se of T. (Brackets, , (3 3, 84 , 8 4 4 ( None ( , , 8 ( , 84 , 8 , 8:

>>> player1 = None


>>> player2 = None
>>> player3 = None

4 , 8 , , 8 4 if-statement &3 , 8 , 8 8 , 84 , 8


se of T. (Brackets)
se of T. (Brackets, , (3 3, 8, 8@ (
4 3, 8, 8@ 4 ( 3, :

>>> if player1 is None or player2 is None or player3 is None:


... print('Please wait until all players have returned')
... else:
... print('You have raised %s'%(player1+player2+player3))

if-statement ( , 8 8 , 8 -& ( , 8, 8 , 8, 8@ ( None ( 3, 8, , 8 , 3, 8, 8@, ( none
, 8 4 3, 8 & , 8, ( , 8 ( , 8 ( , , 8 -& ( , 8, 8 :) ( 2 ( 4 , 8 4 3, 8 ( v48
& , 8, ( , 8 ( , 8

2 ( , -& ( , 8, 8 None ( 3, 8, , 8 ( 2 3 4 3, 8 3, 8:

>>> if player1 is None or player2 is None or player3 is None:


... print('Please wait until all players have returned')
... else:
... print('You have raised %s'%(player1+player2+player3))
Please wait until all players have returned


, ( ( , , 8 -& ( , 8 X4 ( , 84 -, 8 , 4 Error & , 8, , 84 , 8 , 8

( , 8 -& ( , 8, 8 ( ( 2r 4 3, 8 & , 8, , 84 , 8 :

>>> player1 = 100


>>> player3 = 300
>>> if player1 is None or player2 is None or player3 is None:
... print(Please wait until all players have returned)
... else:
... print(You have raised %s % (player1 + player2 +
player3))
Please wait until all players have returned

, 8, 8, , , 8 -& ( , 8, 8 ( 2 ( 4 3, 8 4 ( v48 , 8 & , 8, , 84 , 8 :

>>> player1 = 100


>>> player3 = 300
>>> player2= 500
>>> if player1 is None or player2 is None or player3 is None:
... print(Please wait until all players have returned)
... else:
... print(You have raised %s % (player1 + player2 +
player3))
You have raised 900

. , 8 2 & 8 ...?

10 '10' , 8 & , 8 2 & 8?

4 34 - , 8 , 8 ' ...' @ , 8 2 & - , , 8#, 82 & ( , 8, 8
4 3, 8 4 , 8 , ( ( , & ( v48 ( ( ( a 4 ( 4 - , 8@ , 8, 8
4 , 8 8 , 8 2 & , 8, 8@ , 8 ( -& ( , 8, 8 , 8 (age) , , 8 ( , & 4
, 8 ( @ if-statement , 8 &:

>>> if age == 10:


... print(you are 10)

( 4 -& ( , 8 age 10 ( 2 , 8 , 4 3, 8 , 8, 8 , , 8:

>>> age = 10
>>> if age == 10:
... print(you are 10)
...
you are 10

( ( age ( 2 '10' 4 3, 8 , 8, 8 ( , 8 :


>>> age = '10 '
>>> if age == 10:
... print(you are 10)
...
, 8 3 ? ( ( a ( , & , 8 & , 8 2, 8 & , 8 ( 4 , 84
:

>>> age1 = 10
>>> age2 = 10
>>> print(age1)
10
>>> print(age2)
10

, 8 @? 4 , 84 , 8, 8 , 8 ( 4 , 8, 8 , 834 ( 3, 8F , & :) ( ( a 4 4
4 age==10 (age equals 10) , ( 4& 3, 8 , ( -& ( , 8, 8 ( ( a
3
, 8 4 , 8@ ( , 8@ ( , 8@ , 8 ( ( , 8, , & , 8 ( , , ( 4 (
, 84 , 8 , 8 ( ( , , , 8 , 8 ( ? , q- &4 , 8 , 8 , 8
, 8 , 8@ ( a - , & , & , 8 ( a - , 8 ( 4 , 84 , 8 , 8 ( -, 8 ,
( , 8 3, 8 ) 3 , 8, ( a '10' , & , 8 ( 42 , 84 (

se of T. (Brackets) &3 :

>>> age = '10'


>>> converted_age = int(age)

-& ( , 8 converted_age 10 , 8 , 8@, ( ( a ( ( , & , 8 ( a -


, 8 ( 4 , 84 4 3, 8 &3 str
se of T. (Brackets) :

>>> age = 10
converted_age = str(age)

-& ( , 8 converted_age '10' , 8 , 8@, ( , & , if-statement


( @ , 8 ( :

>>> age = '10'


>>> if age == 10:
... print('you are 10')
...

( , 8 8 , 8 -& ( , 8 , 8 ( 42 ( 4 3, 8 ( -


se of T. (Brackets)
se of T. (Brackets) , 8 :

>>> age = '10'


>>> converted_age = int(age)
>>> if converted_age == 10:
... print('you are 10')
...
you are 10


, 8 &

( ( , , 8 , 8 ( @ 3, 84 , 8 , 8 , 8 , 8 , 8 , 4 -


4 , 8 , :) - , 84 , 8 , & , 84 , 8 4 8 3? 4 4 , 8 , 8, ,
4 ? -, 8 , 8 - , 88 :), 8 8 8 , 8, 8 2 ( , 8 , ( , , 8 , ?
- , , 8 ( , 8 , , 2 # 3, 8 ( @ ( (
( ( ( ( 4 , 8 , 8 :) , 3, 8 ( , 8 , 8 ( , 4, 8 (
( 2 - ( , 84 , 8 - , 8 , 8 28 , 8 3 4 3, 8 ( 4
, 8 , 8

( , , , 8@J , 8 , 8@J


4 , 8 , , 84 , 3 & , 8 , ( ( - ( , - , 8 , 8 H (
:) ( ( &3 3 , 8 , 8 for-loop 3 , 8, 4 , 8 , 8 , 8 hello
, 8 Y (
se of T. (Brackets , ( , 84 3, 8 , 4 ( 3, 84 ( , 8 , ( &3 , 8-

>>> print("hello")
hello
>>> print("hello")
hello
>>> print("hello")
hello
>>> print("hello")
hello
>>> print("hello")
hello

, 8 ( ( , 8, 8 ( , 84 , 8 , 8 ...

( , 8 for-loop (
se of T. (Brackets) - , 8) &3 , 84 , 8 ( ( : , 8 ( v48 , 8 print
, 8, 8
se of T. (Brackets , 8#, 82 ( spaces
se of T. (Brackets) Y [ &3 3, 8, 8@, , 8 @ ( , ( &3
, 8 ( @ , 84 , 8 , 3, 8 4 , 84 , 8 , 8 [ ( ):

>>> for x in range(0, 5):


... @@@@print(hello)
...
hello
hello
hello
hello
hello

, 8, 8 3 ( , 84 , 8 range ( &4 3, 8, 8@ range 3, 8 (
se of T. (Brackets) ( , 3, 8
, & ( 4 ( X4 ( , 84 , 8 , 8 3 , 8:


>>> print(list(range(10, 20)))
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

4 for-loop , 8 for x in range(0,5) , ( , 8 , 8 ( , 8 2 , 8 , & (


4 ( (0, 1, 2, 3, 4) X4 ( , 8 -& ( , 8 X , 8 & ( 4 ( , & , , 8 , 8 (
X print , 8, 8
se of T. (Brackets &3 , 84 , 8 ( :

>>> for x in range(0, 5):


... print(hello %s % x)
hello 0
hello 1
hello 2
hello 3
hello 4

( for-loop , 8 &3 ( 4 , 8, 84 ( for-loop &3 , 84 4 3, 8 , 8, 8 , (
3, 8 , 8:

x = 0
print(hello %s % x)
x = 1
print(hello %s % x)
x = 2
print(hello %s % x)
x = 3
print(hello %s % x)
x = 4
print(hello %s % x)

4 4 ( ( & , 8 4 , loop , 8 , 8 ( @ , 8 , 3, 84


Y ( , 8 ( ( , 8 8, ( - ( , , 8 38 , 8 (
, 3 - ( ( ( , 84 , 8@J , 8 , 8 ( , 8 - for-
loop 3, 8 :)4 ( , 8 8 , 8
se of T. (Brackets

, 4 28 !!!

( 4 ( 3 , 8 ( , 8 r , 8 , 4 3, 8 4


for-loop , , 8 , ( @ 3 ( 42 , 8 , 8 ( 4 (
, 8 , , ( 3, 84 , 8 , 8 :

IndentationError: expected an indented block

, 8 ( , 84 , 8, 8 4 , 8 , 84 3, 8 ( v48 , 8


se of T. (Brackets) Y [ ( , 84 -
, 8 , 8@ , 8 , 8
se of T. (Brackets) Y [ (, , ( & ) , 8#2
, 8, 8 ( , 8 ( ( 4 , 8 , 8 ...


range &3 , 8 , 8 , 84 , 8W 3, 8 , 8 list ( ( ) &3 , 8 ( @ , 84 , 8 &
X4 ( , 8 ( @ , 8#, 82 & , 8 X4 ( , 8 ( @ 4 ( :

>>> shopping_list = [eggs, milk, fish, banana, potato, meat]


>>> for i in shopping_list:
... print(i)
eggs
milk
fish
banana
potato
meat
, 8, 8 , ( , 8 , list ( 4 ( , 8 , 8 :), -& ( , 8 'i' , 8 & , , 8
4 , 8 -& ( , 8, 8 ( , #3 print , 8 ( ( @, ( for-loop , 8
& 3 ( 4 , 8, 84 , 4 3, 8 , 8 , 8 ( @ &3 , 84 3, 8

>>> shopping_list = [eggs, milk, fish, banana, potato, meat]

>>> print(shopping_list[0])
eggs
>>> print(shopping_list[1])
milk
>>> print(shopping_list[2])
fish
>>> print(shopping_list[3])
banana
>>> print(shopping_list[4])
potato
>>> print(shopping_list[5])
meat

4 , 8 , 84 , loop ( , 8) , 8 , 8 , 8 , 8


, 8

. ( 2, 8 ?

( ( ,
4 ' , ' 8 ?
( , 3, 8 ( ( , 8, 8
se of T. (Brackets ( , , 8 ( , 8, 8 , 8 , 8 ( 4 , 84
3 , 8 , , 8, 8 for-loop 3 ( , 84, 4 ( , 8 , 8 print @ , 8
( @ , 84 3, 84 4 ( ( 4 ( , 8 m , 8 , 8 4 ( print , 8 , 8 ( (
( @, 8 , 8 , 8 ( buy , 8
se of T. (Brackets) , 8, 8@, 4 ( - , 8 , ( ( , 84 , 8 , 8 :

>>> for i in shopping_list:


... buy(i)
... print(i)


, 8 , 8, , 8 , 8, 8 3 ( , 8 - , 8, 8 , , 8
se of T. (Brackets) ( , (
4 ( () , 84 r , 8 4 3, 8 4 ( ( ( 42 (error message) , 8 , 8 ( 3 ( (
, , 8 2 , 8 ( ( , 8
se of T. (Brackets, , , 8 ( W4:

buy(i)
print(i)

, 8 , 8
se of T. (Brackets) Y , & ( 4 ( & 8 , 8 ) , ( 4 ( , 8 , 8 )
, 8#2 , , 8 [ , 8 , 8, 8@ , , 8 , 8 X4 ( :) , 8 , 8 3

this would be block 1


this would be block 1
this would be block 1
this would be block 2
this would be block 2
this would be block 2
this would still be block 1
this would still be block 1
this would be block 3
this would be block 3
this would be block 4
this would be block 4
this would be block 4

( 4 , 8
se of T. (Brackets) Y ( ( , ) ( ( - 8 ( 4 , , 84 3, 8 3 , 8:

>>> for i in shopping_list:


... buy(i)
... print(i)

, 8 ( v48 , 8 (


se of T. (Brackets) buy(i)) 3, 8, 8@ ( , v 4H48 , 8 (print(i)) 3, 8, 8@ (
, v , 8 , 8 , ( 4 , 8
se of T. (Brackets) Y [ (, ) H [ ( (,
, 84 , 8 @ &4 3, 8, 8@):

>>> for i in shopping_list:


... @@@@buy(i)
... @@@@@@print(i)

( ( ( , 8 4 ( ( ( , &3 , 8 , 4, 8 4 , 8 ( , ( , 8 , 84


3, 8 ( 4 ( ( , 8 -& , 8 , 8 ( , 84 , , , 8, 8 -& 8 , 8 :)
, 8 , 84 4 ( , ( x ) &3 , 84 3, 8

4 , 8 , 8, 8@ ( , ( , 8 , , 8 3 ( @ , 84 , 8 4 , 84 , 8 , 8 ):

@@@@heres my first block


@@@@heres my first block


4, 8 ( v48 , 8 ( ( ( -& - , 8, 8@ ) 4 , 8 ( , :

@@@@heres my first block


@@@@heres my first block
@@@@@@@@heres my second block
@@@@@@@@heres my second block

( ( , 8 -& , 8 :) ( , 84 ? , 4 4 (


( v48 ( - , 8 ( , 8 ( -2 , 8 ( , 8 for-loop ( , 3
for-loop ( 3, 4 , 8
se of T. (Brackets , 8 , 8 , 8 , 84 ( v48 , 8 - , 8
, 8 4 ( , 8 ( -2 , 8 , ( W - , 8 , 8
, 8 , 8, , 8 , 4 ( , , 8 , , 8 ( 44 , 8 2 ( , 8 , 8 4
4 (
se of T. (Brackets) Y , 8
se of T. (Brackets 8-4 , 8 ( , 8F ( , 8 , 84 4 ( ( , , 84 , 8 , 8 4 , 8 , 8
4 ( , 8 , 8 , 8 & , 8, 8@ )
, 8 ( @ 3 ( , 8 r ( , 8 , , 8 ( ( ( 4 , ( ( , 8
(, 8 , 8 print , 8 , 84 4 , ( , 8 , 8 , 8 , 8):

>>> mylist = [ a, b, c ]
>>> for i in mylist:
... print(i)
... print(i)
...
a
a
b
b
c
c

( v48 print , 8, 8 ,


se of T. (Brackets) Y , 8
se of T. (Brackets 8 , 8, 8 - ( , 8, , 8 , 8 4 ( ( , 84
4 , 8 ( ( , 8 ( 4 ( , 8 (
se of T. (Brackets , 8
, 8 428 3 ( , 84 ( ( 42 2 , 8:

>>> mylist = [ a, b, c ]
>>> for i in mylist:
... print(i)
... print(i)
...
File <stdin>, line 3
print(i)
^
IndentationError: unexpected indent

( v48 (
se of T. (Brackets , 8 ( , ( , , 8, 8@, ( , 8 , 8 , 2 , 8 , , [ , 8
:) , 8 , 8


, 8 , 8

4 ( ( ( , &3 , 8 , , 8 4 3, 8 4 , 8 (


, ( , 8 , 84 3, 8 ( ( , ( , 8 , 8 4 3, 8 4 , 8
( , ( , 8 , 84 3, 8 ( , &3 , 8 3, 8 ( -
( &3 , 8

( , 8 3 ( , 8, ( 3 :

>>> mylist = [ a, b, c ]
>>> for i in mylist:
... print(i)
... for j in mylist:
... print(j)
...

, 8, , 8 8 3, 84 , 8 , 8@ , 8...?


, 8, ( , 8, 8@- ( 3, 8 for-loop :

>>> mylist = [ a, b, c ]
>>> for i in mylist:
... print(i) #
... for j in mylist: #-- , 8 , 8
... print(j) #
...

( v48 ( 3, 8 ( v48 for-loop (


se of T. (Brackets ( :
>>> mylist = [ a, b, c ]
>>> for i in mylist:
... print(i)
... for j in mylist:
... print(j) # ( ( v48 , 8
...

4 ( 8 , 84 , 8 , 8@ , 8 ( , , 8 , ( 8 , 84 , 8 , 8@ ?


( mylist , 8 ( (
se of T. (Brackets , 84 , 8 , 8@, ( ( 4 (
se of T. (Brackets , 8? ( ( 4 ( , 8
( , 8 ( , 4 3, 8 , 4 , & ( , 84 , 8 , 8 ( , 8 , 8
se of T. (Brackets ( ( , 8
( 4 ( , 8 , 8 , 8 4 , 8 , 8
se of T. (Brackets, , 8 4 ( ( (
se of T. (Brackets , 8 , , 8
, 8, 8 , 8 ( , 8 ( ( , 8 ( 4 ( , 8 , 8 , 8 4 , 8 , 8
se of T. (Brackets, , 8 4
, ( , 8 , 8 , 8 ( , 4 3, 8 a , 8 , , 8 a, b, c, 4 , 8 b , 8
, , 8 a, b, c, 4& ( , 8 , 8, , 8 , ( ( , 8 4 ( , 8 , 8 :

>>> mylist = [ a, b, c ]
>>> for i in mylist:
... print(i)
... for j in mylist:


... print(j)
...
a
a
b
c
b
a
b
c
c
a
b
c

(
se of T. (Brackets , 8, 8 ( , 8#2 ( @ &3 , 8 3? 4 , 8 ( , 8 , 8@,
- , 84 ( ( 3, 8, , 8 ( @ , ( ( @, 8 ( 4 @ 4 4 , 8 4 , 8
4 , 8 , 8@, , 8 , 8 , , 8 ( 3, 8, , 8 ( ( 4 , 8, ( (
se of T. (Brackets) , 8
:) 4 ( , 8, 84 , H ( :) , 8, 84 ( 4 , 8, 4 3, 8
( 3, 8, , 8 , 8 ( @ 4 @, 8 4 3, 8 4 3, 8 ( 3, ( 3, 8 ( , 8:

>>> ( 200+300-250)*12

( 200 + 300 - 250 @, 8 12 , v , 84 3, 8)


( 4 , 8, 8 , 8 4 , , 8@ ? , 8 4 8- , 8 , 8@? , ( , 8 , 8 (
, 8 ( for-loop v , ( ( 3, , 8 ( , 84 , 8 ( ( :) , 8 , 8
, & , 8 , 8 -& ( , 8, 8 ( 3, 8, , 8 , 8 , 84 ( , 84 3, 8 :

>>> tiffin = 200


>>> stipend = 300
>>> spending = 250

# ( 3, , 8 -& ( , 8 , 8 &3 , 8 , 84 , 8 ( :


>>> (tiffin+stipend-spending)*12
3000

, 834 , 84 , 8 ( @ ( 4 , 8, , H ( , 8 , 8F , :) savings , 8 4 , 8 (
-& ( , 8 X4 ( , 8 , 8 loop &3 , 84 3, 8:

1.>>> savings=0
2.>>> tiffin=200
3.>>> stipend=300
4.>>> spending=250
5.>>> for month in range(1,13):
savings=savings+tiffin+stipend-spending
print('month %s=%s'%(month, savings))


, 8 'savings' -& ( , 8 , 3, 8, 8@ 0 v ( , 8 , 84 ( @ ,
, 8 )
( v48 ( for-loop v ( W4 3, 8, 8@, , 8 ( v ( W4 3, 8, 8@ )
se of T. (Brackets,, 8
( , 8 ( 4 3, 8 4 , 8 , 8, month -& ( , 8 , 8 , 8 428 , & , , 8 , 3, 8
4H48 ( ( ( , 4, ( 4 , 8, ( , , (
, , 8 , , 8 , 84 ( , 8 , 8 savings -& ( , 8, 8 , , 8 & , 8 ( , 8@
( (
se of T. (Brackets) , 8 H ( , 8 , 8
se of T. (Brackets) , 8 , ( 4 , 8, ( , 8 , 8 8
& , 8 ( 4 ( , , 8 - , 4H48 , 8 , 8 3, 8 , 42 , v
savings -& ( , 8, 8 ( , 8 ( 4[ , 8 , , 8, , 3, 8 4 , 8 428 , 8, , , 8
, 4, , ( ( (=) ( ( , 8 , 8, , 8 ( , 8 2, 8 , , , 8 , 8 , 8 , 8
, , 8 , 84 4 , 8 4 , 8 , 8 &3 , 8 - ( , 84 &3 , 8 :) 4
, , 84"
4 2 ( ( print , 8
se of T. (Brackets , ( , 8, , & , 8, H4 , 8 (
( , , 8 , 8 2 (
se of T. (Brackets , 8 ( , 8 2 4 , 8@ ( W , 8 3, 8 , 8 4 3, 8 , , 8H
Tricks with Strings , ( , , 8 ( ( , 8 , 8 4 , ( ( 4 ( , 8 ( ( ( 4 ( (
, 84 , 8 , 8:

Month 1 = 250
Month 2 = 500
Month 3 = 750
Month 4 = 1000
Month 5 = 1250
Month 6 = 1500
Month 7 = 1750
Month 8 = 2000
Month 9 = 2250
Month 10 = 2500
Month 11 = 2750
Month 12 = 3000

..... - , 8 , , 8 2 , 84 , 8

. , 834 , 8 ( , 8 , 8 ( @

, 8 , 8 for-loop , 8 , 8 , 8 while-loop , 8, 8@ ( for-loop ( , 8 3
( , 8 4 , 8 , 84 3, 8, 4 3, 8 while-loop 3, 8 ( , 8 , 8 4 , 8
4 , 8 , 84 3, 8 , 8 , 8 , ( ( , Y ( , 84 ( , 8 , 8, 8@ 4 ( , 8 , 3, 8 4 ( (
, 8 ( 4m , 84 , 8 , 8 ( 3, 8 for-loop

>>> for step in range(0,20):


... print(step)
, 8 , 8 ( ( , Y ( , 8 3 , 8 , 8 , 8W, 8@ , 8 3 , 8 #Y W , 8 4
( 3, 84 , 8 , 8 3 ( , 8 ( 4 ( m 4 , 8 , 824 3 :) & , 84
, 8 , 8 ( 3, 8 while-loop


>>> step = 0
>>> while step < 10000:
... print(step)
... if tired == True:
... break
... elif badweather == True:
... break
... else:
... step = step + 1

, 8 ( , ( , 84 ( , 8 - , 8, 8 , , 8 tired badweather -& ( , 8
X4 ( ( , 8 ( ( 4 ( , 8, 8 , ( , , 8 while-loop ( , 8 while , 8
-& ( , 8 step 1000 , 8, 8 (step < 10000) , 8 , ( ( , 8 , 8 , , 8 step
(
se of T. (Brackets ( , , 8 , 8 8 ( tired badweather , 8 & ( , 4& ( tired , 4& 3,
4 3, 8 break , 8
se of T. (Brackets , 8, 8 , ( ( , 8 (# 4 , , 8
se of T. (Brackets) ( , 8 , 8, 8
, 8 , 8 ( W , 8, 8 , 8 , 8 ( ) badweather , 4& 3, 8 , 8 ( tired
badweather , 4& 3 2& ( & 3, 4 3, 8 step , 8 1 3, 8, while loop (step <
10000) 42, 8 , 8 , 8 8 3, 8
4 while loop , 8, 8 3, 8 :
42 , 8 8
, 8 , ( (
, 8
, 8 , - , 8 , 84 , 8 , while-loop , 8 ( 42 ( , 8 ( W4 3, 84 , 8 , 8 -

>>> x = 45
>>> y = 80
>>> while x < 50 and y < 100:
... x = x + 1
... y = y + 1
... print(x, y)

, 8, 8 , 8 ( , 84, ( -& ( , 8 x ( , 8 ( @ 45, -& ( , 8 y ( , 8 ( @ 80
, 8 ( , 84 , , 8 ( 42 , 8 8 , 84 , 8 3, 8F : x, 50 , 8, 8 @ ( y, 100 , 8, 8
@ ( ( 42 , 4&, 4 , ( ( ( , 8 , , 84& (x y) -& ( , 8, 8 1 , 8
3, 8 4 , 8 (
se of T. (Brackets 3, 8 , ( , 8 3, 8 , 8:
46 81
47 82
48 83
49 84
50 85

3, 84 ( 4 Y, 8 , 84 , 8 , 8 , 8, 8 , & , 8 (


se of T. (Brackets 3, 8 ?
While-loop , 8 ( , &3 3, 8 , ( ( 2- , 8 # 4 , 8,
, 8 ( 42 @ ( ( , 84 , 8 , 8 3 ( , 8 -


>>> while True:
... lots of code here
... lots of code here
... lots of code here
... if some_condition == True:
... break

, 8, 8 , 8, while-loop 42 'True' :) ( , 8 , , 8 , , (- , 8 , 8 (
3, 8 ( ) ( -& ( , 8 some condition , 4& 3, 8 , , 8 , 8 3, 8
, 8 4 , 8 42 while-loop 3 , 8 ( ( r C-4 , 84 , 8 , 8 ( , (
& , ( ,, 8 , , , 8 2), ( 4 , H ( r
se of T. (Brackets) , 8 , 8#, 82 , 8 428 & , 8 , 8 2 , 8, 8 , 84
3, 8

(-& ( , 8 x- 45 -& ( , 8 y- 80 [ , 8 , 8 ( @ ,


4, 8 , 84& , 8, 8 , (, 8 , 8@) ( 4 ( -& ( , 8, 8 1 , 8 H ( , 8, 8, 8@
42, 8 , 8 8 , 8 x, 50 , 8, 8 , y, 100 , 8, 8 @ ( , 8 Y , 8 (
, 8 ( ( 4 , 84& -& ( , 8, 8 1 3, 8, 8@) x 3 50 4 42 ( (x < 50)
, 4& , 4 :) , 8 , 8 , 8 ( , 84 3, 8)


. ( , 8 r , 8

& , 8 ( :) 8- , 8 , 8 &3 , 84 3 , 8, 8


( -4, 8 , &3 , 8 ( @ , 8 ( :)

8 8

( ( ( 4 , ( , 8 8 , 8 4 ?

>>>for x in range(0, 20):


...print(hello %s % x)
...if x < 9:
break

8 8

4 ( & , 8 , 8 , 4 & 4 , 8 3, 8 , 2 & 4


&3 :) 4 , 8 ( @ 2 , 8 , ( 4 @ & 4 H4 , 8 2 , 8 ( - ( , 8
, 8 2 , 4 4 & , 8 , ( 4 , , 8 3, 8 , ( 4 , 8
( 4 , 8... ( 8- , 8? ( , 8 :) 4 ( 4 , ( , 8 @
, 8 , 8 ( , 84 , 8 , 8 ( 2 :) 4 &3 3 4 ( ( , 8 4 ( , (
, 8 , 8 , 8 & 4 , 8 H4 ( , 8 , 8@ 1000 ) :) 1% (4 1 - )
, 8@, 4 3, 8 4 ( H4 , , 8 0.01 , 8 ( ( 3, ( 3, 8 1000 X 0.01
, 8@) ( 4 2 - , 8@, 4 3, 8 4 ( H4 , , 8 0.02 , 84 3, 8 ( 4 (
100 & , 8 , 8 , & ( 4 , 8 ( 4 @ 3% , 8 , 4 3, 8 ( 4 @ 4
, 8 ( 4 3, 8, - , 8 10 @, 8 4 3, 8? ( ( 2 :) 4 , 8 for-loop &3
, 84 3, 8 4 3, 8 ( ( ( , 84 3, 8 (, 8 , 84 3, 8 , , 8 , 84 3, 8)


&

&4 ? 4 3, 8 ( , 8 &3 , 8 & !!


( , 8 4 ( 4 ( 4 ( 4 4 2 X4 ( , 8 ! , 8 ( , 8, 4 , ( , 8, 8,
, 8& , 8 ,
se of T. (Brackets, , 8 ( ,
se of T. (Brackets)
se of T. (Brackets) , , 8 , 8 ( , 8 , , ( , 8 , 8 , 8& , 8 , ( , 8
( , 8 & , , 8 & , , , 8 ( , & ( 4& ( , 8 ( @

, 8 , 2 4 ( , 8W , 8 #, 8 , 8 3, 8 3, 8 , 8 4 ?

, 4 , 3, 8 , 8 , 8, 8 r ! #, 8, 8 # , 8W (


, 8! - & 3, 8 & ( 4m 3, 8 4 ( 2 , 8 , 8 - , 8 #, 8 , 8
, 8 , 8, 4 - , 8 &3 ( , ( ( , 8 ( , 8
- Y, 8 4 , 8 ( , 8 4 4 X4 ( 3, 8 , , 8 , 8 &3 , 8 :) , 8 , 8 ( 4
3, 8 ( , 8 , 8 , 8 , 8 4 ( ( , 4 3, 8 , 8 4 ( , 8W 3 3
2 #, 8, 8 ( , 8 , 8 , 8, 8 H 3, 8 , 8 , 8H ( 8 , 8H, 8 ( , 8 ( - , 8
( ? Y, , 8 , 8 ( ( , , 8 &3 , 8 -& , , 84 3, 8 4 3, 8 &4 #, 8, 8
, 8 3 , 8 , 8H ( 8 4 , , 8 &4 3 , 8
( ( - ( , , 8 ( &3 , 8 2 3 , 8 ( , 8 (
3


. , Hr ( &3 , 8 #, 8 , 8 , 8 , 8, 8 ( , 8 , 8 , 8, 8 , 8
. , ( , 8 , , 8 , 8 3, 8

, 8 ( , 8 , 8 , 8 , , 8 ( ( - , , 8 &3 , 84 , 8 &
( , 8 , 8 ( @ & - ,
se of T. (Brackets) - &, 8 2 ( , ( , 8
se of T. (Brackets) , 8
( , 8 , , &3 , (
se of T. (Brackets) , 8 3 ( , 8 ( (
r ( :

>>> def myfunction(myname):


... print(hello %s % myname)
...

, 8, 8 3 ( , 84


se of T. (Brackets) , 8 3, 8F myfunction , 8& ( myname. , 8 , 8& (
# 4 , 8
se of T. (Brackets) , 8 ( , , 8 & , 8 , 8F, def ( ( W , 8 , 8
se of T. (Brackets) , 8
4 , 8& ( ( , 8 , ( , 8 3, 8, 8@ (def , 8 , 8 , ( , , 8 definition
, ( , 8) , 8, 84 , 8& ( , 8 ( , 8
se of T. (Brackets) ( :

>>> myfunction(Nipun)
hello Nipun

( , 8& ( ( , 8 :

>>> def myfunction(firstname, lastname):


... print(Hello %s %s % (firstname, lastname))
...


se of T. (Brackets) , 8 , 84 , 8 :

>>> myfunction(Nipun, Ahmed)


Hello Nipun Ahmed

( , 8 ( @ X4 ( , 8


se of T. (Brackets) , 8 &3 , 84 , 8 ( :

>>> fn = Asif
>>> ln = Tanvir
>>> myfunction(fn, ln)
Hello Asif Tanvir

, 8
se of T. (Brackets ( 2 (return statement) &, 8
se of T. (Brackets) , 8 , 8
se of T. (Brackets) 4 , 8, 84 , 8 ( :

>>> def savings(tiffin + stipend - spending):


... return tiffin + stipend - spending
...
>>> print(savings(200, 300, 250))
250

, 8, 8
se of T. (Brackets) , 8 ( 4 ( , 8& ( ( & ( , 8& ( (tiffin stipend) , 8

se of T. (Brackets) , 8 4H48 , 8& ( (spending) ( , 8 3, 8
se of T. (Brackets)
se of T. (Brackets) , 8 :) ( , 8


( 3, 8, , 8 &3 , 84 , 8 , 8 :) :) - - , 8 , , 8 3 , 8 , 8 &3
, 84 , 8 , 8

>>> my_savings = savings(20, 10, 5)


>>> print(my_savings)
25

( & , 8 3, 8F


se of T. (Brackets) , 8 # , 8 (body) &4
se of T. (Brackets) , 8 &3 , 8 & :

>>> def variable_test():


... a = 10
... b = 20
... return a * b
...
>>> print(variable_test())
200
>>> print(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name a is not defined

, 8, 8 3 ( , 84 variable_test


se of T. (Brackets) X4 ( , 8 ( @ , 8 ( (a b) 3, 8, 8@

se of T. (Brackets) print , 84 , 8


se of T. (Brackets)
se of T. (Brackets) , 8 , 8 200 , 8 ( a b print , 84
3 4 3, 8 ( ( 42 , 8 , a is not defined 2 'a' , ( 4 ( ( -
, 8 3 'scope'

se of T. (Brackets) , 8 , , 8 - , v8, 8 ( 3, 8, , 8 , 84 , 8 , 8 , 8 :) , Y4, 8 , 8
3 484 , 8 , 8 v8, 8, 8 , 8 ( , 8 , 8 , , 8 , 8
se of T. (Brackets) , 8 , 84
( , 8 , 8 , 8 , 8
se of T. (Brackets) , 8 , 8& ( ( 3, 8, , 8 , 84 , 8 , 8 ) , 8 , v8, 8, 8
( , 8 ( 4 ( , 8 , 8 , 8 , 8 ( 42 , 8 , 8 4 - ( 42 , 8 , 8 , 4 (
, , 8
se of T. (Brackets) , 8 (, 8 , 8 , ( ( 2 return value) 4 ( , 8 42 ,
, 8 4 4 , 8, 8 , , 8
se of T. (Brackets) , 8 ( , 8 4 , 84 ( @ , 8, , 8 scope
, 8, 84 , 8 ( ( ( , 84 ( 3 v8, 8, 8 ( , 8 ( ( , 8 , 8@
-# ( , 84 ( [4 , 8 2 -# ( , 84 , , 8 , , 8 &3 , 8
, 84 , 8 , 8 4 3, 8 3, 8 4 3, 8F:

>>> x = 100
>>> def variable_test2():
... a = 10
... b = 20
... return a * b * x
...
>>> print(variable_test2())
20000

2 , ( a b
se of T. (Brackets) , 8 , 8 &3 , 8 &
se of T. (Brackets) , 8 , 8 , Hr x ( W &3 , 8 &
3, 8, 8@ 4 , 8 Y , 8F v8, 8, 8 :) ( , 8 4 , 8 8 & ( , , 8 , 8 , 8 , 8


( , 8, 42 , 8 &3 3, 8F 4 &3 , 84 , 8 , 8

, 8 for-loop &3 , 8 - , 8 , 8 @, 8 , , 8 ( @ 4 , 84


, 3, 8 , 8 (
se of T. (Brackets) , 8 &3 , 84 , 8 ( :

>>> def yearly_savings(tiffin + stipend spending):


... savings = 0
... for month in range(1, 13):
... savings = savings + tiffin +stipend - spending
... print(month %s = %s % (month, savings))
...

, 8, , 8 ( ( - , 8 :) , 8, 8 , 8 ( 4


se of T. (Brackets) , 8, 8 r , 8 :

>>> yearly_savings(200, 300, 250)


Month 1 = 250
Month 2 = 500
Month 3 = 750
Month 4 = 1000
Month 5 = 1250
Month 6 = 1500
Month 7 = 1750
Month 8 = 2000
Month 9 = 2250
Month 10 = 2500

(continues on...)


>>> yearly_savings(25, 15, 10)
month 1 = 30
month 2 = 60
month 3 = 90
month 4 = 120
month 5 = 150

(continues on...)

, 8 ( 4 for-loop ( 4 ( - ( - , , 8 , , 8 , 8 , 8 (


se of T. (Brackets)
4- , 8 &4 3 4 4 , 8 , 8 ( , , 8 , 8 ( , , 8#2

, 8, 8 ( , , , , 8 2 , 8 ...

. ( ( , 8, (Bits and Pieces)

( , , 8 , 8 , 8 , 8 , ( m- , 8 , 8 8


se of T. (Brackets) ( , 3 , 8 , 8 &

se of T. (Brackets) , 84 , 8 & &3 , 8 ( @ ( :)
se of T. (Brackets) ( , 8 ( ( , 4 ?

( . gedit ( , save ,

se of T. (Brackets) , 8


se of T. (Brackets) , 8 &3 , , , 8 2 , 84 ( ( , , , 8 ( @ ( , 8 File (
, 8 Save , 8, 8 ( , 8 , 8 (
se of T. (Brackets) (placeholder-%s) : Desktop ( 2 , 8
se of T. (Brackets) , 8 'test.txt'
( ( .)
, 8 , 8, , 8 ( :

>>> f = open(Desktop/test.txt)
>>> print(f.read())

( , @ , v ( , 8 3, 8F ( 3, 8F


se of T. (Brackets) , 8
se of T. (Brackets) , 84 , 8& (
( 3, 8, , 8
se of T. (Brackets) ( 4 ( X4 ( , 8 @ 4 3, 8, 8@
se of T. (Brackets) ( ( ( , 8 (value)
( 2 (return) , 8 , 8 ( 4
se of T. (Brackets) , 8 , 8[ , 8 , 8 ( , 8 , 8 , 8 , 8 (Object) 3


, 8 , 8& ( v , , (
se of T. (Brackets) , 8 3, 8F
se of T. (Brackets) , 8 [ ( , 8 2 3, 8F 2

se of T. (Brackets) , 8 , 8 f - , 8 & , ( 4

, 8 428 (
se of T. (Brackets) , 8 , 8 :) ( ( , 8
se of T. (Brackets) (read)- (call) , 8 , 8@
se of T. (Brackets) , 8
, 3 , 8 &
se of T. (Brackets) , 8 ( , 8, 8 , 8, , 8 4 , 8 ( , 8 2 3, 8F , 8 , 8F f -
( & , 8 , 8 :) read
se of T. (Brackets) &3 3, 8, 8@ f read , 8 & , (.) ( &4
3, 8, 8@

, 8 , 8 ( & Appendix B , 8 , 8 , 8



se of T. (Brackets) X4 ( , , , 8 2 , 84 , 8 , 8

. ( , (Modules)

, 84 , 8 & ( , &3 , 8 , 8 ( 4 , , , 8 2 , 8


se of T. (Brackets) , 8 ( @ , 8 , 8

se of T. (Brackets) ( , 8 X4 ( , 84 , 8 ( , 8 , 8 , Hr
se of T. (Brackets) ( : range and file, int and str) &3
, 84 , 8 ( , 8 ( , 8
se of T. (Brackets) , 8 , 8@ , 8 , 84 , (.) 48, 8 &, 8 , 8

se of T. (Brackets) , 8 ( 4 , 8 &4 3 , 8 3 ( , 'time' ( ,, 8 ( 3


( , 8:

>>> import time

import
se of T. (Brackets, ( , 8 , 8 , 8 3, 8, 8@ ( ( ,, 8 , 8 ( , 8, 8 3 ( , 84
3, 8F time ( ,, 8 , 84 , (.) 48 &3 , 8 ( ,, 8 ( & , 8
se of T. (Brackets)
, 8 ( , 8 , 84 , 8 ( :

>>> print(time.localtime())
(2006, 11, 10, 23, 49, 1, 4, 314, 1)

, 8 , 8F, time ( ,, 8 -& , 8 localtime (


se of T. (Brackets) ( , 4 ( ( 2
, 8 ( 2 , ( , , 8 , 8H , 8H , 8 , 8 - , 8 2 , , ( 2 , 8
@ , , , ( , , ( ( , , , 8
se of T. (Brackets,, , , 83 ( , @, 8 ( , ( , 3 , 8 (
( , 8 , 8 , (daylight savings) , 8 , ( 3, 8, 3, 8F ( 4 , 8, 8 , 84
, 8 , 8 ( ( , 8 , 8 , , 8 ( 3, 8, 3 4 3, 8 , , 3, 8 ( 4 ( , 8H
( , 8 (Tuple) , ( 4 3 ( & , 8 , 8 4 ( , 8 ) time
( ,, 8 &, 8 localtime 4 ( , , 8 ( 2 , 8 4 , 8 ( ,
4 ( , , 8 , 8 , 8 ( , 84 , 8 ( :) , 8 , 3 & , 8 (
se of T. (Brackets) &3
, 84 3, 8:

>>> t = time.localtime()
>>> print(time.asctime(t))
Sat Nov 18 22:37:15 2006

, 8 ( &3 , 8 , 8, 8 ( , 84 , 8 ( :


>>> print(time.asctime(time.localtime()))
Sat Nov 18 22:37:15 2006

, 4 (
se of T. (Brackets) ( ( , 8 &3 8 ( ( , 8 , 84 , 8 , 8 print
( &3 , 8 4 ( ( , 84 , 8 , 8 :) time ( , - , 8 , 8, 8 2 , 8 @ ( W , - , 8
'sys' ( , , 8, 8 2 , 84 3, 8

import sys

sys ( ,, 8 'stdin' , 8 ( , 8 , 8@ , 8 3 short for standard input 2 , , 84
, ( , 8 stdin- ( , (readline) , 8 , 8 8 , 8 ( 4
se of T. (Brackets) , 8@ 8, 8 , 8,2 , 8 H4
, 8 , 84 , 8 , 8 Enter 8 , 8 , 8 2 3, 8F 4 ( ,
se of T. (Brackets) , 8 , 84 , 8 , 8, , 8
, 8, , 8 ( , 8
se of T. (Brackets, ( , 8 ( , , 8 8 , 8 ( :

>>> print(sys.stdin.readline())

, 8 ( 4 ( , 8 , 8 Enter , 8, 8 4 3, 8 ( , 8 , 8 ( @, 8 4 , 8, , 8 ( 4
3, 8 3#, 84 2 :) , 8#, 82 , , 8 r , 8 if , 8
se of T. (Brackets &3 , 8 4 ( , 8
se of T. (Brackets) , 8 :

if age >= 10 and age <= 13:


print(you are %s % age)
else:
print(huh?)

4 , 8 ( , , 8
se of T. (Brackets) ( ( , 8 4 , 8 , 8 , 8 , ( , 84 2 , , 84
4 3, 8 , 8 ,
se of T. (Brackets) , 8 , 8 ( :

>>> def your_age(age):


... if age >= 10 and age <= 13:
... print(you are %s % age)
... else:
... print(huh?)
...

, 8& ( , 8 ( 3, 8, , 8 ( , 8 , 8 , , 8 ( , 8@ ( , 8 , 8 8 , 8
:

>>> your_age(9)
huh?
>>> your_age(10)
you are 10

(
se of T. (Brackets) ( , 8 , 8 , 3, 8 , 3, 8 4 ( - , 8
& ( , :)
se of T. (Brackets) ( , 8 ( 42 , 84 , 8 , 8 :

>>> def your_age():


... print(Please enter your age)
... age = int(sys.stdin.readline())


... if age >= 10 and age <= 13:
... print(you are %s % age)
... else:
... print(huh?)
...

, 8, 8 readline & ( (text) ( a (string) ( 3, 8, , 8 , 8 , 8 4 ( 2 , 8 , 8
, & , 8 , 8 :) , 8 int
se of T. (Brackets) &3 , 84 3, 8 , 8 4 if , 8, 8
se of T. (Brackets , ( W - , 8
, 8 4 ( , 8 , 8 , 8 8 , 8 , 8 ! , 8& ( @ your_age
se of T. (Brackets) (
call 'Please enter your age' , 8 ( @ ( , 8
se of T. (Brackets) :

>>> your_age()
Please enter your age
10
you are 10
>>> your_age()
Please enter your age
15
huh?

, 8 , 84 3, 8 , 8 , 4 ( , & ( 3, 8, , 8 - , 8 , readline , ,


string ( 2 , 8

, 8 , 8 , 8 , 8 ( , &4 3 sys time 4 , 8 , 8 &
( ( , , 8 , 8 &4 :) :) ( , , , , 8 2 , 84 Appendix
C


. , 8, ( , 8 ( :

& , 8
se of T. (Brackets) ( , &3 , 8 , 8 , 8 , &3 , 8 ( , , , 8 2
- 'scope' ( , 8 ( , , 8 ),
se of T. (Brackets) , 8 , 8 ,
se of T. (Brackets) , 8 -4, 8 &3 , 8 (
def &3 , 8 8- , 8
se of T. (Brackets) , 8 X4 ( 4 (

8 8

& , 8 8 8 @, 8 ( , 8 ( for-loop X4 ( , 8 ( @


for-loop , 3, 8
se of T. (Brackets) ( 3, 8, , 8 &3 , 84 , 8 ( @, 8 , 84 , 8 2 , 8 ( , 8 3 , 3
(
se of T. (Brackets) X4 ( , 8 3, 8:

calculate_interest(100, 0.03)

8 8

, & X4 (
se of T. (Brackets) , 8 ( ( 2r , , 8 , 8 4 3, 8 4 , 8 - @ @
, 8, 8 , 8, 3, 8:

calculate_interest(100, 0.03, 5)

8 8


se of T. (Brackets) ( , 84 , 8& ( , 8 , 3 , 8 & , 8 , (pass) , 8 ( , 842 ( @ ( X4 (
, 84 , 8 ( , 8
se of T. (Brackets) ( , 8 , 8 (sys.stdin.readline()
se of T. (Brackets) &3 , 8 ) , 8, 8
, 8& ( @
se of T. (Brackets) ( , 8 call , 84 , 8 , 8

calculate_interest()

@ ( ( X4 ( , 84 , 8 4 (


se of T. (Brackets) , 8 , 8 3, 8 float float , , , 8 2
, 8 ( ( ( ( @ int
se of T. (Brackets) , 8 , 84 ( ( @ & ( 4m , 8@ ( string- (
, 8, 8
se of T. (Brackets , 8 (floating point numbers) , 8 , 8 Floating Point Numbers 3, 8 ( , & (.),
- . .


, &

se of T. (Brackets) ( , 8 ( @ &

4 34 , 84 , 8 & , 8


se of T. (Brackets) (

, 8, 8 ,
se of T. (Brackets) & ( , 8 ( ( -
se of T. (Brackets) :) , 8 ( , 8 , 84
, 8 , 8@ , ( ( ( , ( ( @? 3 ( a, 8 , , 84 , 8 , 8 ,
4 , 8 & - 4 , 8 8 , 8, 8 ( , 8 3, 84 , 8 , 8@ , 8 , 8 , 8
3, 84 , 8 , 8 ) J , 8 , 3 , 8 , ( , 8 , 8 , 3, 8
se of T. (Brackets) & ( , 8
se of T. (Brackets) (
, 4
se of T. (Brackets) , 8
se of T. (Brackets) , 8 , , 8 , 8, , , 8 @, 8 ( 3 4 , , 8 , 8
, 8 , 8
se of T. (Brackets) , 8 , 8 , 8 ( @ , 8 , 8 - , 3, 8 , 8
,
se of T. (Brackets) , 8 , 84 ( , 8, 8@ 2
se of T. (Brackets) , 8 , 8 , , 8 ( , 8 , 8 , 8#2
4 & -
se of T. (Brackets) ( ( ,
se of T. (Brackets) ( , 84 ( , 8 4 & , 8@,
se of T. (Brackets) ( , 8 3, 8, 8@,
se of T. (Brackets) ( , 8
&3 3, 8, 8@ 4& (
se of T. (Brackets) , 8 ( & ( , 8 ( ( , 8 , 8 ? ( ( - 4 & , ( 4

se of T. (Brackets) , 8 , 8 ( @, 8 , 8 , 84 , 3 & , 8 , 8 , 8 - , 8 (
, 8 , 8 , 8
se of T. (Brackets) , 8 , 84 , 8 8, ( , 8 8
se of T. (Brackets) , 8 - , 8
J , 8 , ( , 8 , 3 ( , , 8 , 84 , 8 ( ( ,, 8 ( (directories)

se of T. (Brackets) (placeholder-%s) , 8 (folder) &, 8 , 8


se of T. (Brackets) , 8 , 8, 8 , 8 , 84 , 8 (
se of T. (Brackets) , 8
( , 8@, 4 ( ( , , 8
se of T. (Brackets) , 8 , 8 , 84 , 8 (
se of T. (Brackets) -

se of T. (Brackets) , 8 , 8 & 8 , 8 4 & , 8 , ( , , 8
se of T. (Brackets) , 8 , 8 & , 4 &
, 8 , 84 , 8 (

, 8 & , 8 , 8 ( @ , 8 , 8 8- , 8


se of T. (Brackets) , 8 X4 ( , 84 3, 8- , 8
se of T. (Brackets) , 8
# & , 4 & , 8 , 84 3:

>>> f = open(c:\\test.txt)
>>> print(f.read())

f.read() , 8 4 , 8 34 , 8, 8@ ,


se of T. (Brackets) ( , 8 ? -
se of T. (Brackets) , 8 , 8 4 &
, 8 , 4 ( 4 4 4 & 4 , 8 , 8 ( 4 ? Y, X ( , 8,
( , 8
se of T. (Brackets) , 8 , 8 , 8 ( , 84 , 8 (

, 8, , 8 , 8


se of T. (Brackets) ( :), , 84 4 , 8 ( , 8
se of T. (Brackets) ( , 84
( , 84

>>> f = open(myfile.txt, w)

open()
se of T. (Brackets) , 8 ( -4, 8 ( 4 ( "w" ( (
se of T. (Brackets) , 8 , 8, 8 ( , 8 , "w"
, 8 , 8 , 84 , 8 , 8
se of T. (Brackets) ( , 84 3, 8 , 8 :) , 8, ( @ :

>>> f = open(myfile.txt, w)


>>> f.write(this is a test file)

( ? (
se of T. (Brackets) , 8 4 , 84 ( , 8 ( "this is a test file" , 8 (
, 8 , 8
se of T. (Brackets) ( , 8 , 8, , 8@, ( , 8 ( @ ( , 84 ( , 8 , 8 , 8
, 8 , 8 ,
se of T. (Brackets) ( , 8 ( :) 4 3, 8
, 8 ( , 84 3, 8 ( , 8 , 84 , 8

>>> f = open(myfile.txt, w)
>>> f.write(this is a test file)
>>> f.close()

f.close() , 8 , 8


se of T. (Brackets) ( , 8 ( , 8 F , 8 ( , ( 4& ( , 8 , 8@ ? , 8, , 8 8 , 8 (
( , &3 , 8 myfile.txt
se of T. (Brackets) ( , 8 ( , 8 , 8 , 8 , 84 , 8 (

se of T. (Brackets) ( , 8 , 84:

>>> f = open(myfile.txt)
>>> print(f.read())
this is a test file

( , 4 ? , 8 ( J , 8
se of T. (Brackets) , 8 , 84 ( , 84 , 8 , 8 ? ( , 8 ( , 8 ( @ 8
, 8 ( ( 4 , 3 3, 8 , 8@


r &

F, 8, 8

4 , 8 ( , 8 , 8@ & , 8 "turtle" ( , ( , 8 , 8 ( @ , 8


& - , 8, , 8 @ ( Y :) , 84 , 8 , 8 ( , ( , 8 , 2 , 8 'Pen' , 8 X4 ( , 8 ( , 84
3, 8 ( @ ( W , 8 :

>>> import turtle


>>> t = turtle.Pen()

( @ ,
se of T. (Brackets) &3 , 8 & - , 8, , 8 @ F, 8 , 8 [ , 8 , 8 [ , 8
( , 8 ( , 8 ( ( - , H ( 4 X4 ( , 84 , 8 ( , 8 & , 8 2 Y, 8 ( @ :

>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)

, 8 for-loop &3 , 8 ( , 8 , 84 ( @, 8 ( , 84 , 8 ( :

>>> t.reset()
>>> for x in range(1,5):
... t.forward(50)
... t.left(90)
...

- , 8 ( , 84 , 8 , , 8 , 8 ( @ :


( .: F, 8 ( ( J (
4 Y, 8
se of T. (Brackets)

>>> t.reset()
>>> for x in range(1,9):
... t.forward(100)
... t.left(225)
...

, 8, 8 , &3 , 8 r q ( 4 ( Y 3 ( . 4 ( 3 ( F, 8 (


( 4 ( , 8, 8 , , 8 ( , 8 ( , (8 )

, 8 , 8 , 8 ( 42 ( ( , (8) 82 , 8 ( ) &3 , 8 , 8 8 , 4


X4 ( , 84 , 8 ( :

>>> t.reset()
>>> for x in range(1,38):
... t.forward(100)
... t.left(175)
...

, 8Y , 8 4 X4 ( , 84 , 8 ( :


>>> for x in range(1,20):
... t.forward(100)
... t.left(95)
...

( .: , 8 8 4

( .: , 8 8 4


( .: 4

, 8 ( ( @ ( :

>>> t.reset()
>>> for x in range(1,19):
... t.forward(100)
... if x % 2 == 0:
... t.left(175)
... else:
... t.left(225)
...

, 8, 8 , 8, , 8 8 , 8 ( @ x , & ( - :) , (modulo) , 8 , 8
(%) &3 , 8 ( @ - if x % 2 == 0

x % 2 # :) 3, 8 ( x v ( - & 3, 8 ( , 84 , 3 4 3, 8 , 8 ( , 8 (


, 8 , 8 "x % 2 == 0" &3 , 8 , & , 8 8 ( , , 8
( 4 , 8

4 ( , & ( ( 4 , F, 8 ( ( ( -
se of T. (Brackets) , 8 , ( , 8 , 8 ( @ Y , 84 , 8 , 8
:

t.color(1,0,0)
t.begin_fill()
t.forward(100)
t.left(90)
t.forward(20)
t.left(90)
t.forward(20)
t.right(90)
t.forward(20)
t.left(90)
t.forward(60)
t.left(90)


t.forward(20)
t.right(90)
t.forward(20)
t.left(90)
t.forward(20)
t.end_fill()
t.color(0,0,0)
t.up()
t.forward(10)
t.down()
t.begin_fill()
t.circle(10)
t.end_fill()
t.setheading(0)
t.up()
t.forward(90)
t.right(90)
t.forward(10)
t.setheading(0)
t.begin_fill()
t.down()
t.circle(10)
t.end_fill()

, 8 , ( , 8, , 8 , ( , 8 , 8 ( , 8 , 8 , 8 ( ( : .- 4 @ (


, 84 , 8 , 8 ( , 8 4 ( @ ( ( , ( : &3 , 8- , 8 , 8 (
, 8 ( 42 , 8 ( , 84 3, 8- , 8 & - , 8, ( ( ( 2r ( , 8 , 8#2 , 84 3, 8- , 8 ( ( 2r , 8, 8
( H Y , 84 3

color
se of T. (Brackets) ( ( , 8& ( (3 , 8 ( , ( v48 ( , , 8 , 8& ( ( 8 -
, 8 ( ( , 8 2 , 8 , 8 # 4 ( ( (RGB) , 8 ( , 8, 8 &, 8 ( ( ( 2r
se of T. (Brackets) ( , 8 4 ( @


( .: F, 8 ( , 8 ( Y , , 8 ( W !!!

, , 8 ?

( 4 ( , 8 ( ( - ( , 8 , 8 4 3, 8 4 ( , 8 , 84 , 8 & , 8 @ 4 (


( - ( 4 :) , 8 ( , 8 8 4 , 8 8,
, 8 , 8 , , 8 4 , 8 4 , 8 8 ( , , 8 4 ( - , 8 , 84 , 8
, , 3 , 8 , 8 - & ( 4m ( , , 8 , 8 , 4

( , &3 ( @ , ( ( 4 ( , 8 , 8 , 8@ , , ,


8 , 84& ( , 8 , 8#2, , 8 ( , , #2 , 8 , 8 3 ( %) , 8 , 8
, (%) , 8 , 4 , 84 , , (%) ( @ , 8 , 8 ( , 8
3 3, 8 , 8 4, 8 , 8, 3 H X4 ( ( F, 8 , 8 ( , 8

>>> t.color(1,1,0)
>>> t.begin_fill()
>>> t.circle(50)
>>> t.end_fill()

, 8, 8 3 , 8 color


se of T. (Brackets) , 8 % , % , % 8 &3 , 8 ( @ , 3, 8
( , 8 , 8 8 - ( 8 :) , 8
se of T. (Brackets) , 8 , 8 ( 4 , 84 , 8 (

>>> def mycircle(red, green, blue):


... t.color(red, green, blue)
... t.begin_fill()
... t.circle(50)
... t.end_fill()
...


( , H Y , 84 , 8 ( , , &3 , 8 (%):

>>> mycircle(0, 1, 0)

( , H Y , 84 , 8 ( , 8 2 , (%) ( , 8 :

>>> mycircle(0, 0.5, 0)

, 8 , , 8 ( , 8 - , 8 , 8 , 8 , 8 , 8 4 ( 4 &3


, 8 ( , , 8 , 8 ( , 8 ( @ , 4 &3 , 8
, , 8 , 8 2 , 8 , 8 3 , 8 , 8 , 8 , & ( 3, 84
, 8 4 , , 84 , , 84 (
se of T. (Brackets) , 8 3, 8 , 8, , 3 - 2 ( , , 84 , , 84 3, 8 , 8, , 8 4 ( , 8
( , 8 r , 8 , 8#2 2 , 8#2 8 2 8 H Y, 8 8 [ 3:

>>> mycircle(1, 0, 0)
>>> mycircle(0.5, 0, 0)
>>> mycircle(0, 0, 1)
>>> mycircle(0, 0, 0.5)

- , ( , 8 X ( & , 8 , 8 , 8 , 8 , 8 , 84 , 8 , 8 % , %
, 8 &3 , 8 :

>>> mycircle(1, 0.85, 0)

3 , 88 , 8 , 8 % , % , % 8 &3 , 8 :

>>> mycircle(1, 0.70,0.75)

, 8 , 8 % , % , ( ( , 8 , 8 8 , 8 , 8 % , % ,


% 8 ( ( , 8:

>>> mycircle(1, 0.65, 0)


>>> mycircle(0.6, 0.3, 0.15)

, , 8 & - , , 8 ( , 84 , 8 , 8 &3 , 84 3, 8 t.clear()

F , , 84 , 8 ( ( -, 8 4 ( 3? , ( @ 3, 8


( W , 8 2 , 8 4 , , 8

4 ( ( H, 8 , 8 , 8 , ( 4 ( , 82 0 4 3, 8 , ( (


, 82 H X4 ( , 8, ( .- 4 , 84 , 8 , 8

>>> mycircle(0, 0, 0)


, 8 , ( 4& ( , , 8 % , 8 4 3, 8 , 2 , 8 , 8

>>> mycircle(1,1,1)

. ( , 8 -

4 ( 34 4, 8 , 84 , 8, 8 @ fill


se of T. (Brackets) ( , ( m , 84 3 , 8& ( ( 3, 8, , 8 - 1 , 8 , , 8
( ( , 84 0 &3 3 , 8 ( ( ( 4 ( , 84
Y, 8 ( @ , , 8 ( , 8 - , 8 4, 8 :)
se of T. (Brackets) ( , 8 , ( m , 8
H ( 4 #&4 Y , 84 3, 8 4 - , 8 , 8 , 8 , &3 , 8
, 3, 8 ( 2, 8, 8 ( , 8 , 8#2 , 84 , 8 ( 4, 8 , 8 2, 8 Y ( ( , 8 (
se of T. (Brackets) , 8
, 8 ( 4 2, 8 Y , 84 , ( ( :

( .: ( , 8 H

>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)

se of T. (Brackets) ( 3, 8, , 8 , 84 , 8 ( 2, 8, 8 , 8 , 8& ( ( 3, 8, , 8 , 8 , , 84
se of T. (Brackets) (
&3 , 8 , 3 3, 8:

>>> def mysquare(size):


... t.forward(size)
... t.left(90)


... t.forward(size)
... t.left(90)
... t.forward(size)
... t.left(90)
... t.forward(size)
... t.left(90)


se of T. (Brackets) ( , 8 , 8 8 , 8 , 84 , 8 ( - , 8:

>>> mysquare(50)

( , 8, 8 , , 8 2, 8 ( 4, 8 forward(size) left(90) , 8 H (


, 8 ( @ 4 r , 8 for-loop &3 , 8 , 3, 8 ( , 84 , 8 ( - , 8:

>>> def mysquare(size):


... for x in range(0,4):
... t.forward(size)
... t.left(90)

, 8 , , 8 4 ( , 84 , 8, 8 ( ( - ( , 8 r


:

>>> t.reset()
>>> mysquare(25)
>>> mysquare(50)
>>> mysquare(75)
>>> mysquare(100)
>>> mysquare(125)

( .: , 8 , 8 2, 8

, 8, 8 ( , 8 4 H ( 4 X4 ( 3, 8


( , 8 , 8#2 2 X4 ( r ( , 8 & - , ( , 8 , 8 ( , 8 :

>>> t.reset()

fill
se of T. (Brackets) , 8 , ( m , 8 2 Y ( :

>>> t.begin_fill()
>>> mysquare(50)

fill
se of T. (Brackets) , 8 ( ( , 8 2 2 , 8

>>> t.end_fill()

( , 8 @ ( 4 ( 2 , 8:

( .: ( , 8 2, 8


se of T. (Brackets) ( , 8 - , 8 , 8 ( 42 ( &3 , 8 v , 8#2 38
2, 8 Y , 84 , 8 ( :) , 8 , 8 ( , ( , 84 3, 8 :

>>> def mysquare(size, filled):


... if filled == True:
... t.begin_fill()
... for x in range(0,4):
... t.forward(size)
... t.left(90)
... if filled == True:
... t.end_fill()
...

, 8 , 8 8 , 8 ( filled , 8& ( , 8 True ( ( True 3 4 3, 8 fill



se of T. (Brackets) , 8 , ( m ( , 8, 8 &, 8 2 ( Y , 8 , 8 8 , 8 ( filled , 8& ( , 8
True ( ( True 3 4, 8 fill
se of T. (Brackets) , 8 ( ( , 8 ( , 8 - H4 2
Y , 84 , 8 ( - , 8:

>>> mysquare(50, True)

@ 2 Y :):

>>> mysquare(150, False)

( .: ( 2, 8, 8

, 8, 8 , , 8 ( H ( 4 , 8 , 84 , 8 2 H ( 4 , 8 4


- , 8 4 ( , , 8 H ( 4 X4 ( , 84 , 8 , , 8 , 8 ( , 8 - , 8 ( , 84 , 8
, 8 4 ( Y, 8 ( @ , 8, , ( , 8 (
se of T. (Brackets) , 8 , 8 ( 4 ( ( @ , 8 , ,:

>>> for x in range(1,19):


... t.forward(100)
... if x % 2 == 0:
... t.left(175)
... else:
... t.left(225)
...

mysquare
se of T. (Brackets) , 8 4 if-statements &3 , 84 , 8 ( size , 8& ( ( , 8
forward
se of T. (Brackets) , 8 , 8 , , 84 , 8 (

1. >>> def mystar(size, filled):


2. ... if filled:
3. ... t.begin_fill()
4. ... for x in range(1,19):
5. ... t.forward(size)
6. ... if x % 2 == 0:
7. ... t.left(175)
8. ... else:
9. ... t.left(225)
10. ... if filled:
11. ... t.end_fill()

filled , 8& ( , 8 , 8 , 8 ( - ( , 8 , 8 ( , 8 - (


4 , 8, ( W 4 , 8 ( size , 8& ( , 8 , 8 &3 (
( 3, 8, , 8 , 8 2 &3 ( 4 , 8 , 8 , 8@ , 8 2 , 84 %
, % , % 8 , 8
se of T. (Brackets) ( , 8 :

>>> t.color(1, 0.85, 0)


>>> mystar(120, True)

( .: ( , 8 4

, 8, 8 @ ( 4 2 8 4 X4 ( 3, 8 4 2 , 8 ( 42 , 8 X4 (


, 84 , 8 ( :

>>> t.color(0,0,0)
>>> mystar(120, False)

( 3, 8, , 8 (
se of T. (Brackets) ( ( ( , 8 , 8 ( 4 Y, 8 ( @ & - , , 84 ( , 8
4 3, 8


. ( , 8 (

& , 8 F, 8 ( , , , 8 ( , 8 ( @ 4 &3 , 8 ( @ , & ( ( 4 Y , 84


( , 8 ( @
se of T. (Brackets) &3 ( , 8 ( @ , 8 ( @ , , 8 &3 :)
se of T. (Brackets) , 8
, 3, 8 ( ( - ( , 8 ( ( - H ( 4 Y , 84 , 8, 8 ( @

( .: ( 3, 8 , 3 ( , 8 4

8 :

2 Y, 8 ( @, Y , 8 3? , 8 ( , 8

(, #: ( , (8 , 8 ( , 8 r , 84 3, 8)

8 :

, ( , 8
se of T. (Brackets) , 8 , 8 ( 4 , 84 3, 8 , 8 2 v - , 84 3, 8


&

( ( (
se of T. (Brackets)

( @ &3 , 8 @ ( Y , ( 3 ....... ( @.... ................ 8 ..... ( 4 !!!

( ( ( @ 4 , , 82 ! ( 4, 84 ( , 8 , 4 ( 8 ( 4 , , 8 ( @, 8 :) (


& , 8 , 8 ? 4 , 8 r 4 , , 8, 8@ ( 4 ( ( , ( (
se of T. (Brackets) ( , 8
, 8 4 ( ( , 8 , ( 4 ( , 8
se of T. (Brackets , 8
se of T. (Brackets, , ,- ( , , 8
, 8 , 4 3, 8 , 842 :) , , 8 ( (
se of T. (Brackets) ( , 8 ( ( 4 8, 8 , 84 , 8 )
, 8 -4 ( (
se of T. (Brackets) 2 ( ( - , 8 , 8, 8@ : ( 3 , - ( , ( 2 ( v ( ) , , 8 , 8
( , #3 , 4 3 , 8 ( , 8 , - , 8 - ( - , 8 , 84 , 8 , 8
( , 8
se of T. (Brackets , 8
se of T. (Brackets, ,
se of T. (Brackets) , 8 , , 84 , 8 , 8, 8@ , 8, - 8 ( , (
( ( ) , , 8 , 8 ( ( @ , 4 3, 8 , 8 , ( , 8 , 8 ( , 8 , -
, 8 - ( @ ( , 8 , 84 , 8 , 8 , 84 3 3, 8 & ( ( ,- ,

se of T. (Brackets) , 8 , 8 , 84 , 8 , 8, 8 , 8, 8@ 8 ( , ( ( ( ) , 8 8, 8
( 24 ( , 8 4 , 8 , 8r 3

, ( (
se of T. (Brackets) 2 , 84 , - , 8 ( ( ( , , 8 3, , ( 3 8, 8 44 , , 8
4 ( ( & ( , 8 r , 8 @? , 8 4 ( , 8 ( , 8& , , 8
4 ( , 8H ( @ , 8 (3, 84 , 8 , 8 ( , 8 @ ( ) , 8 428 , 8H 4 (
@ ( Y , 8 4, 8 ( , 8 ( @ , , 8 , , 8 , 8 428 , 8H 4 ( @ ( Y , 8 , 8
( , 8 , , 8 , , 8 - , 8 4 ( ( @ , 8H , 84 @ ( ( Y , 8 3, 8 4 4 (
, 8H , 8 , 8 4 4 , 8, ( 44 , , 8 4 ( , 8H 4 3, 8 , 8 3, 8 ( 3 Y , 8@ , 8,
( ( -, 84 ( 24 , & ( , 8, 8 ( 3 q ( , 8 4 ( ( @ Y , 8 4 , 8 4 (
Y , 8 ( ( @ , 8 ( ( 424 , 8, 8 - , 8 2, 8 , 8 ( ( , H ( r 3 , 8 ( @
, ( (
se of T. (Brackets) , 8 , 8 :) ( 4 ( @ ( Y , 84 , 8 , 8 3, 8 @ ( (
, 8@ 4 3, 8 4 , 8 ( 4 ( , 8 @ ( 44 , , 8 , 84 3, 8 , 8 , ( , 8
4 ( ,

( ( ( (
se of T. (Brackets) , 8 , 8 ( v ( ( (
se of T. (Brackets) , 8 r - , 8 X4 ( 3, 8 , 8 , ( 4 , 8 q (
, 8 ( , 8 4 ( @ ( ( , 8 Y, 8 , 8 4 , 8 428 , 8
:) , 8 4 , 84 3, 8...


. 4

8, 8 :) ( - ( - ( ( - ( - ( - , 8 ( 4 , 8 , 8 ( @ , 8 ( 4 4 ( 4


( @ , 8@ 8 ( 4 , , 8 3, 8F , ( ( , 8 , 8 8 , 8 :) X4 ( , 8
, 8 4 , 8 , 8 ( ( - ( 2 & , 8 , 8 ( , 8- , 8 , 4 2 , 84 3, 8

, 8 , 8 ( (
se of T. (Brackets) , 8 , 8 :) ( @ ( - , 8 , 8, 8@ ( , 8 & , 8, 8@ , 8#, 82 , 8 ( @ v
, 8 , 8 ( 4), ( , 4 ( (
se of T. (Brackets) - :) , , 8 ( 4 3, 8F ( , , 8, , 8' 8 , 8 , 8
, , 8 , ( 4 , 8 4 , 8 , 4 , 8 ( , 8' 8 &3 , 8 , 8
@ ( ( , 84 3, 8


, q- &4 , 8 , 8 , , 8 ( ( , , 8, 8@ , , 3 , 8 & q ( ( (
se of T. (Brackets) , 8 , 84 , 8
( ( @, 8 , 84 ( @ 4 ( 4 , , ) , 4 4 4 ( , 84 , 8 ( Quick Draw
Turtle 4 , 8 ( @

( , ( 3 tkinter ( ? 4 4 ? , 8 3, 8F 'Tk interface' ' (


se of T. (Brackets , 8
se of T. (Brackets) , ')
, 3 , 8 & ( , 8 ( , 8#2 & ( , 8 X4 ( , ( Y, ( 4 ( , 8 , 3 , 8 & (
, ,2 , 8, , ( X4 ( , 8
se of T. (Brackets) , 84 , 8 , 8) , , , 8 , , 8
, 8 , , 8 ( , & ( , 8 X4 ( , 84 , 8 ( ( , 8 , 8 , , , 8 :

>>> from tkinter import*


1. >>> tk=Tk()
2. >>> btn = Button(tk,text=click me)
3. >>> btn.pack()

, 8, Tk ( ,, 8 ( , 8, 8 2 , 8 ( @, , 84 4 &3 , 84 , 8 ( -, 8 , 8 &
, , 8, 8 8 3, 8F Tk, ( q ( , 8
se of T. (Brackets, X4 ( , 8 , 8 428, 84 , 8 & , 8 ( @
, , 8 , 84 , 8 ( 4 ( ( v48 ( ( , 8 , , 8
se of T. (Brackets, ( 8, 8 ( 24 3, 8 4H48 , 8,
( 4 X4 ( btn -& ( , 8, 8 4 & , , 8 tk , 8 (
, 8& ( ( 3, 8, , 8 , 8, 8@ , 8 , 8& ( ( 3, 8, , 8 , 8, 8@ , 8 'click me'.


, 8 , 8& (
, 8 , 8& ( &3 ( @ ( ( , ( ,
, 8& ( , 8 4 , 8 , & ( 4m 3, 8F ( , 8 , 8 - , 8 , ( ( r
3, 84 , 8 , 8 , 4 , 8 , 8 :) ( ( 2 , 84 3, 8

3 , 8 , 8 , 8 rectangle (


se of T. (Brackets) , 8, 8@
, 8 , 8& ( , 8, 8@ width 2 [ height 2 ! 4
, 4 ( 4 3 rectangle(200, 100) - , 8
se of T. (Brackets)
( , 8 3, 8F rectangle [ ( , 8, 8 ! 4
( , 8, 8 ( ( 3, 8 ( , 8& ( , 8 , 8 3, 8 ? 2
, 8& ( , 8 , 8 m , 8 ( 3, 8? , ( @ , 8 3, 8
, 8 4 ? 4 3, 8 , 8 ( ( ? ( ! 4 (
[ 4 , 8 ( , 84 3, 8 : rectangle(height=100, width=200)
, 8 3 , , , 8 , 8 , 8& (
&3 , 8 ( ( , (
se of T. (Brackets) , 8 , 3 - , 8 :) &3
3- ( ( , , , 8 2 ! 4 , 8 2 , 8 , 84 , 8
3, 8 , 8

, 2, 8 2 , 8 , 8 ( , 8 2 3 ( , 8 ( , 8 :) , 8


, 8
se of T. (Brackets, X4 ( 3, 8 ( @ 4 ( @ , 8 H ( 4 , 8 , 84 ( , 8 'click me'.
, 84 , 8 3, 8:

( , , 8 , 8 , 4 ( , 84 ( , 84 , 8 , 8 ( ( @ 3, 8 , 8


( , 8 , 84 , 8 , 8#, 82 3 ( ( @ , 8 ( 42 , 8 (4 , 8 ( ( 4 3, 8 , 8#, 82
, 8
se of T. (Brackets, ( 4 ( , 8 @) , 8 (
se of T. (Brackets) X4 ( , 84 , 8 ( ( @ , 8, 8
se of T. (Brackets , 8 :):

>>> def hello():


print('hello there')

, 8 , 8#, 82 , ( , 8 ( 42 , 84


se of T. (Brackets) ( &3 , 84 , 8 , 8 :

>>> from tkinter import*


>>> tk=Tk()
>>> btn=Button(tk,text=click me,command=hello)
>>> btn.pack()

, 8 , 8& ( 'command' , 8 ( , 8F hello


se of T. (Brackets) ( &3 , 84 , , 8 (


3, 8 ( 4 ( , 8 ( 4 3, 8 , 8 'hello there' ( , , 8@ 4 4 ( , 8 (
, 8 44 4 ( ( , 84 , 8 , 8

. ,

8, 8 :) ( , 3 -4 , 8 4 ( , 8 X4 ( , 8 , , 84


3, 8: ( & - , & - , X4 ( , , , 8 [ ! 4 , 8 ( , 84 3, 8, ( X4 (
, ( , 8
se of T. (Brackets, , 8& ( , 8 ( , 8 ( @ , 8 2 & @ 8
, ( @ , 8 , 8, 4:

>>> from tkinter import *


>>> tk=Tk()
>>> canvas=Canvas(tk,width=500,height=500)
>>> canvas.pack()

, 8 3 , 8 4, ( v48 , 8 , 8 ( , 8


se of T. (Brackets, ( 24 3, 8 , 8
& - , ( , 8& (pack) 3W , 8 H ( 4 H ( , 8 , 8 ( , 8, 8 [ &3 , 8 (
, 84 , 8 ( [ , #3 3 & - , 8, , 8 ( , 8, 8, 8 [ ( , 8 (Tk) & - , 8, ,
[ , #3 , 8 & - , ( 4 3, 8 ( , 8 , , 8) 4 3, 8 (, 8 , 8
( , 8) , 8 , x-axis , 8 ( y-axis.

, 834 & - , ( ( , 8, 8 ! 4 ( , 8, 8 , 4 ( , 8 , , 8 [ 3, 8 ,


4 ( . , [ , 8 , [ , 8 ( , 8:

( .: & - , x y ( ,

>>> from tkinter import*


>>> tk=Tk()
>>> canvas=Canvas(tk, width=500,height=500)
>>> canvas.pack()
>>> canvas.create_line(0,0,500,500)


( ( , ( @, 8 , 3 , 8 & , 84 3, 8 , 8 ( , 8 , , 8 3, 8 :

>>> import turtle


>>> turtle.setup(width=500,height=500)
>>> t=turtle.Pen()
>>> t.up()
>>> t.goto(-250,250)
>>> t.down()
>>> t.goto(500,-500)

4 , 84 , 8 & tkinter , 8, ( 4 , ( 4 3, 8, 8@, @ 3, 8, 8@ , 8, 8 4
H , 3 3, 8, 8@
& - , 8, :) , 8 ( 4 , 8, 8@, ( @ , 8, 8@ , 8 &3 , 8 , 8, ( 4 , 8

se of T. (Brackets) , 8 ( @ 28 3 (

( @, 8 ( , 8 , , ( @, 8 , , 8 , 84 , 8 ( @, , 84 , 8 ( @, , , 8 , 84
, 8 ( @ - , 8 , 8 , 8, 8 ( @ - , 8 ( 4 2
Y , 84 , 8 ( tkinter , 3 , 8 & 2 4 , 8, 8 H4 , 3 -4 , 8
, 84 3, 8 , 8 [ , #3

>>> from tkinter import*


>>> tk=Tk()
>>> canvas=Canvas(tk,width=400,height=400)
>>> canvas.pack()
>>> canvas.create_rectangle(10,10,50,50)
1

, 8, 8 3 , 8 ( & - , X4 ( , 8 ( @ ( , 8, 8 ( , 8, 8 4
, 8, 8 ( 2, 8 , 8 ( @ (, 8, 8 , 8, 8 , 8 ( , 8, 8 ( -4, 8
( , 8 , ( , 8 , , 8 ( , 8, 8 ( -4, 8 ) 4 ( 34 , 8 , 8 4 ( , ( , 8 4
( , 8@ 4 ( ( , 8, 8@ , 8#, 82 4 create_line
se of T. (Brackets, ( , 8 ( @, 8 4 , 84
, 8, 8 ( @, 8 ( ? 3, 8F 4 ( H ( 4 @ ( Y, 8 @ (2 , 4 , H 4& ( ) 4
, 8 , 8 428, 84 ( , 8 , 8 , 8

, , 8& ( , 8 ( @ 4 3 : , 8, 8 , 8 x [ , , 8, 8 , 8 y [ , ( , 8


, , 8 x [ ( , 8 , , 8 y [ ( , 8 2 , [ , 8 x1, y1 x2,
y2 , 8 ( , 84 , 8 ( x2 , & v , 8 ( 42 , 8 4, 8 , 84 , 8 ( :

>>> canvas.create_rectangle(100,100,300,50)

y2 ( , & , 8 ( , 84 , 8 ( :

>>> canvas.create_rectangle(100,200,150,350)


, 2, 8 4, 8 ( # 4 , 8@: & - , 8, , 8, 8 , 8 ( , 8, 8 , , 8 , , 8 , 8
( , 8, 8 ( , 8 , 4 , 8 ( ( , 8, 8 , , 8 ( , 8 ( , 8, 8 ( , 8
, 8 4 3, 8 #, 842 4 & - , ( , 84 ( . 4 3, 8

& - , ( , 8 ( ( - H ( 4 4, 8 v , 8 ( , 8#2 ( random ( ,


&3 , 8 ( , 84 , 8 , 8 random ( , , 8, 8 2 :

>>> import random

4 , 8 [ ( 3, 8, , 8 , 8 , 8, 8 &3 , 8 (


se of T. (Brackets) X4 ( , 84 , 8 , 8

se of T. (Brackets) &3 4 randrange:

( .: tkinter , #3

>>> def random_rectangle(width,height):


... x1=random.randrange(width)
y1=random.randrange(height)
x2=random.randrange(x1+random.randrage(width))
y2=random.randrange(y1+random.randrange(height))
canvas.create_rectangle(x1,y1,x2,y2)

, 8 randrange &3 , 8 4, 8, 8 , 8, 8 , 8 :) ( -& ( , 8 X4 (
, 8 ( @, , 8 [ ! 4 , 8 ( @ randrange
se of T. (Brackets) 2, 8
se of T. (Brackets ( 3, 8, , 8 (3 , 8
(randrage , , , 8 2 , 84 Appendix C ) 4 randrage(10) 4 , 8 , 8 , 8 &
, & , 8, randrange(100) 4 , 8 , 8 , 8 & , & , 8 , 8 428
( , 8 , , 8 4, 8, 8 ( 2, 8!) :) -& ( , 8 X4 ( , 8 , 8 , 8, 8 , 8 (x1
y1) [ &3 , 8 ( @ , 84 , 8 , 8, 8 , 8 ( @ , 2, 8, 8 create_rectangle

se of T. (Brackets) , 8 ( @ -& ( , 8 &3 :) 4 ( 4 & - , 8, [ ! 4


, 8 random_rectangle
se of T. (Brackets) &3 , 8 r , 8 , 84 , 8 :

>>> random_rectangle(400,400)

4 8, 8 , 8 ( , 8#2 , 8


se of T. (Brackets) , 84 , 8 , 3, 8 ( ,
se of T. (Brackets) ( :) (
, 8 X4 ( ( ?

( .: , 8 , 8, 8 , 8 , 8 4, 8

>>> for x in range(0,100):


random_rectangle(400,400)

, & - , 8, ( H - , 8 4, 8 X4 ( , 8 ( ( .) ( ( (

4 ( , 8 , 8@ 4 & , 8, ( @, 8 ( 4 ( , 8 4 ( , 8 ( @ ( , , , 8 )


( @ ( , 8 ( @ ? Tkinter &3 , 8 4 , 84 , 8 , 8 4, 8 ( ( @ (
, 8 , 8 , 8, 8 4, 8, 8
se of T. (Brackets) , 8 ( 42 4, 8 ( ( - v , 8 ( , 8#2 :

>>> def random_rectangle(width,height,fill_colour):


x1=random.randrange(width)
y1=random.randrange(height)
x2=random.randrange(x1+random.randrange(width))
y2=random.randrange(y1+random.randrange(height))
canvas.create_rectangle(x1,y1,x2,y2,fill=fill_colour)

create_rectangle
se of T. (Brackets) ( 'fill' ( , 8& ( (3 , 8 , 8#2 &4 3
( , 8
se of T. (Brackets) , 8 r , 8 :


>>> random_rectangle(400,400,'green')
>>> random_rectangle(400,400,'red')
>>> random_rectangle(400,400,'blue')
>>> random_rectangle(400,400,'orange')
>>> random_rectangle(400,400,'yellow')
>>> random_rectangle(400,400,'pink')
>>> random_rectangle(400,400,'purple')
>>> random_rectangle(400,400,'violet')
>>> random_rectangle(400,400,'magenta')
>>> random_rectangle(400,400,'cyan')

( @ , 4 , , H4 , 8 ( ( @ ( 42 2 , 84 , 8 , 8 ( ( -2


, 8 4 ( , 8
se of T. (Brackets, , & ( ( &3 @ 4 , 8 ) , 8 2 ( , 3 (
( , 82 4 &3 , 84 4 3, 8 ( ? ( @ ( ,, 8 , 82 X4 (
, 8 ( @ % , % , 8 &3 , 8 tkinter , 82 X4 (
, 84 , 8 ( &3 , 8 4 3 :

>>> random_rectangle(400,400,'#ffd800')

, 82 X4 ( :) ? 4 ( , 8 '#ffd800' 3 , ( , (hexadecimal)


3, 8F , & , 8 :) ( , 8 ( - , 8 3 , ( , , 8 4 2 , 84 , 8
:) ( 2 ( 4 , 8H , & H ( , 8 , 8 4 , 8 44 3 , ( , X4 ( :) 4 ( ( , 8

se of T. (Brackets) &3 , 84 , 8 :

>>> def hexcolor(red,green,blue):


red=255*(red/100.0)
green=255*(green/100.0)
blue=255*(blue/100.0)
return '#%02x%02x%02x'%(red,gree,blue)'

% , - , 8 &3 , 8 3 , ( , , 82 X4 ( ( :

>>> print(hexcolor(100,85,0))
#ffd800

4 ( # 8 , 82 X4 ( , 84 , 8 % , % , % 8 &3 , 8 :

>>> print(hexcolor(98,1,77))
#f902c4

, 8#, 82 X4 ( , 8 , 8, 8 4, 8 :) , 8 &3 , 84 , 8 ( :

>>> random_rectangle(400,400,hexcolor(98,1,77))


( .: ( # 8 , 82 4, 8

. H, 8 , 8 ( ( ( , 8 ( )2 :

2 3, 8F H, 8 ( , ( tkinter , 3 , 8 & ( Y , 84 3, 8 4 , 8 ( 4, 8


, 84 3, 8 ! ( 4 , 8 2 ( 4, 8, 8 , 8 & 2 @ 44
( & 3, 8 ( ( . ) 2 , ( 3, 8 :

>>> canvas.create_arc(10,10,200,100,extent=180,style=ARC)

, & - , 8, , 8, 8 , 8 , [ [ , 8 , 8 ( & - , 8, ( , 8, 8 , , 8 ( , 8
( , 8, 8 ( , 8) ( , 8 , , 8 , [ [ , 8 , 8 ( ( , 8, 8 , , 8 ( , 8, 8
( , 8) , 8 428 , 8& ( ( ( , 8 , 8& ( ) 'extent' , 8 2 , 8 ( , (8 :) &4 3
( 4 ( H, 8 ( , 8 2 ) ( , (8 , , 8 , 8 , 4 3, 8 , 8 , 8, ( 4 ( ( H , , , 8 2
- , ( , (8 3 4 , 8 2 ( , 8 2 , 8 2 ), ( , (8 3 ( , 8#2 H, ( , (8 3, 8F H, 8
4 2 ( , (8 3, 8F .... ( @ , 8 ( @ , 3 ( - ( - 2 , 8 v
4 ( ( - ( - ( , (8 q ( , 8 2 & , 84 , 3, 8 ( ( . 4 ( 3 , 84 , 8 ):

( .: 4, 8, 8 -4, 8 ( 2


>>> canvas.create_arc(10,10,200,80,extent=45,style=ARC)
>>> canvas.create_arc(10,80,200,160,extent=90,style=ARC)
>>> canvas.create_arc(10,160,200,240,extent=135,style=ARC)
>>> canvas.create_arc(10,240,200,320,extent=180,style=ARC)
>>> canvas.create_arc(10,320,200,400,extent=359,style=ARC)

. , 8H

, 8, 8 ,, #, 83 , ( ( , 8H , 8 4 ( create_oval


se of T. (Brackets) &3 , 8 , 8H
( , H ( 4 H , 84 , 8 , 8 , 8
2 4 , 8H, 8 4, 8, 8 -4, 8 , 8 , 84
3 3 , 8, ( , 8 , ( :

>>> tk=Tk()
>>> canvas=Canvas(tk,width=400,height=400)
>>> canvas.pack()
>>> canvas.create_oval(1,1,300,200)

3 ( ( , 8H , 8 ( ( , 82 -4, 8 ( , 8, 8, 8 [ , , 8


, ( ( : .) ( [ , 8 ( , 8 4, 8 ( , 4 3, 8 4
- - , 8 , 8 ( - , 8 -4 , 8H 3 ( ( : .):

>>> canvas.create_rectangle(1,1,300,200,outline=#ff0000)

( , 8H, 8 , 8 ( , 842 ( , 8#2 H 3 4 3, 8 4 , 8 ( , 82 -4 ( ( : .):

>>> tk=Tk()
>>> canvas=Canvas(tk,width=400,height=400)
>>> canvas.pack()
>>> canvas.create_oval(1,1,300,300)

( .: , 8 2 ( ( - ( , (8


( .: ( , 8H

( .: 4, 8, 8 -4, 8 , 8H


( .: ( , 8#2 H

( .: ( ( -

. -

- 3, 8F ( 4 ( 4 ( ( ( r ( H 4 ( - , 2, 8, 4, 8, , 8- , -


4& ( 3, 8F -, 8 3 , , 8 4 ( , 8 , 8 ( ( 4 H ( 4 - X4 ( , 84 , 8 , 8
3 , 8 4 ( ( ( ( - , 84 4 3, 8 4 , 8 ( 4 , [ , 84 3, 8 ( (
. ):


>>> from tkinter import*
>>> tk=Tk()
>>> canvas=Canvas(tk,width=400,height=400)
>>> canvas.pack()
>>> canvas.create_polygon(10,10,100,10,100,50,fill=,outline=black)

, 8 ( , 8 , &3 , 8 ( ( ( 4 - , 84 , 8 ( ( . , 8


- , 84 , 8 ( F

>>>canvas.create_polygon(200,10,240,30,120,100,140,120,fill=,out
line=black)

( .: ( , ( -

. , 8

4 ( tkinter & 3 , 8 & - , 8, , 8 , 8 , 84 , 8 :) , 8 , 8 , , 84 3, 8 ,
, 8 & - , , 8 , 8 , 8 create_image
se of T. (Brackets) &3 , 84 3, 8 , 84 , 8 q ( , 8 3,
( ( , 8 , , , 8 , 8:

1. >>> from tkinter import*


2. >>> tk=Tk()
3. >>> canvas=Canvas(tk,width=400,height=400)
4. >>> canvas.pack()
5. >>> myimage=PhotoImage(file='test.gif')
6. >>> canvas.create_image(0,0,image=myimage,anchor=NW)


, 8 , 8 4 , 8 & - , , , 8 ( @ , 8 myimage
-& ( , 8, 8 , 8 ( , 8 , 3, 8, 8@ , 8#2 , 4 ( , 8 ( , 8 , , 84 4
, 8 , 8 , 8 v , 8, 8 &
se of T. (Brackets) (placeholder-%s) , 8 , 8 , - , 8 , 8 , 8, [ , 8 , 8@
, , 8
se of T. (Brackets) (placeholder-%s) , 8 3 , , 8, 8 - 3 4 ( ( ( , 8 , 8 ( , 8 , 8 4 , 8
:) getcwd()
se of T. (Brackets) &3 , 84 3, 8 , ( ( , 8 3 :

( .: ( , 8

>>> import os
>>> print(os.getcwd())

, 4 '/home/yourname'... 48 ( @ 2 , 8 4 ( 24 ( ,, 8 ( , 84 ( , 8 , 8 (


, 8 2 , 4 ( 3 Esha, 4 3, 8 getcwd() 4 , 8 , 8 '/home/Esha'
'/home/esha' , 8, 8 ( -2 , 8@ 4 ( , 8- , 8 , , 8 , 8 @ ( ( , 8 , 8 @
4 , 8

( ,, 8 ( , 84 4 @ ( ( ( , 8 4 , 8 PhotoImage


se of T. (Brackets) v 4 , 8 , 8 , (
, 8 4) 4 , 8 4 ( create_image
se of T. (Brackets) &3 , 8 , 8 , 8 & - , 8, , 8 ( 2 , 84
, 8 , 8 ( 8) ( , ( @ ( W 4 4 3, 8 4 ( ( . 4 ( @ , 84
, 8 , 8 (@ ( ( 3, 8 )

PhotoImage
se of T. (Brackets) .gif, .ppm, .pgm , 8 , 8 , 8
se of T. (Brackets) , , 84 , 8 , 8 ( 4 (
:) , 8 , 8
se of T. (Brackets) , , 84 (, 8
se of T. (Brackets) X4 ( :) , 8 , 8 , 8, 8@ -- 3 , 8,
( , ( & , 8 , @ ( 4, 8 4 , 8 3, 8F .jpg), 4 3, 8 4 , 8 , 8 , 84 3, 8


, 8 , 8 , , 8 ( , &4 , 8 The Python Imaging Library

(PIL) , 8 , 8 , , 8 , &4 , , 8 , , 8 , 8 @ , , 8, 8
, 8 ( 42 , , 8 ( , 8 4& ( ( ( , 8 , 8 ( , Python Imaging
Library 4 &3 , , 8 ( , 8 -#2

( .: ( ( - , 8 2 ( , 8 , 8@

. q ( & ( , 8

, 8 2 , ( [ ( ( , 8 , 8 ( @ --- , , 8 , 84 , 8 , 8 & ( , 8
3, 8 3? & ( , 8 :) Tk ( 8 & , 4 , 3 , 8 & q (
& ( , 8 , 84 , 3 3 , 8, ( , 8 , &3 , 8 ( , 8 , 8#2 ( - X4 (
, 84 , 8 ( 8 , 8 , 8 ( , 8 , 84 , 8 ( :

1. >>> import time


2. >>> from tkinter import*
3. >>> tk=Tk()
4. >>> canvas=Canvas(tk,width=400,height=400)
5. >>> canvas.pack()
6. >>> canvas.create_polygon(10,10,10,60,50,35)
7. 1
8. >>> for x in range(0,60):
9. canvas.move(1,5,0)
10. tk.update()
11. time.sleep(0.05)

4 ( ( ( , 8 8, 8 , 8,2


se of T. (Brackets , 8, 8 , ( - ( 8, 8 , 8 , 8 , 8 ( (
. 4 4 , 84 , 8 F ( , , 8 ( , 8 , 8 2 ( , 8, 8@ )
The Python Imaging Library , 8 , 8, http://www.pythonware.com/products/pil/index.htm


8- , 8 , 8 ?

, 8#, 82 , 8 ( @, - 3, 8F ( & - , 2, 8 ( q ( , , 8 -


( ( - Y, 8 ( @ (create_polygon
se of T. (Brackets) &3 , 8 ) - , 8@
se of T. (Brackets) , 8
, 8 (, & ) - - , 8 2 :) ( , for-loop , , 8
, 8 ( @

- 3, 8F ( - ( , 8 [ :) ( ( 4 , & - , 8, ( [4 , 8 [ :)


x
y ( , 8 2, 8 , 84 3 , 8 - , 8 ( ( -#, 8 , 8) ( , 8, 8
, , 8 ( , 8 ( , 8, 8 ( , 8 ( , 8 [ ( 4 3, 8 , 8 ( , 8@, 8 ( , 8 [ ( 4 :)
( , 84 3, 8 canvas.move(1, -5, 0).

4, 8 tk , 8 , 8 , 8, 8,


se of T. (Brackets) , 8 , 8, 8, :) , 8 ( ( , 8, 8,
se of T. (Brackets) &3
3 4 3, 8 ( - [ ( 4 3 , 8#, 82 , 8 3, 8 , 8 2 tkinter , 8, 8 , 8, 2 , 8 , 8
[ , 8 , 8 , 8 ) , , 8, 8 - 4 , 8 4 [ , 8 , 8#, 82 , 8 , 8 . , , 8 , 8
se of T. (Brackets,
:) , 84 3, 8 ( move(1, 5, 5) ( , 8 , , 8 ( 42 , 8 4 3, 8 ( - ( , 8 2 ( , 8
( , 8 ( - , 8 , 8 & - , ( , 8 (, 8
se of T. (Brackets, , 8, 8 ( , 8 X , 8 ( , 8 ) ( , 8 , (
( , 8 ,

>>> i mport time


>>> tk = Tk()
>>> canvas = Canvas(tk, width=400, height=400)
>>> canvas.pack()
>>> canvas.create_polygon(10, 10, 10, 60, 50, 35)
1

>>> for x in range(0, 60):


... canvas.move(1, 5, 5)
... tk.update()
... time.sleep(0.05)
...

( . , 84 , 8 ( F ( - ( , 8 2 ( , 8 ( , 8 , 8@ -5, -5 ( , 8 , 8 , 8@, 8 ( , 8
(
se of T. (Brackets) ( , 8 :

>>> import time


>>> for x in range(0, 60):
... canvas.move(1, -5, -5)
... tk.update()
... time.sleep(0.05)


. ( ( , 8-
se of T. (Brackets (Reacting to events. . .)

Event Bindings &, 8 ( 8 4 , 8 ( -, 8 ( 4 ( m , 84 , 8 ( (


, , 8 4 , 8-
se of T. (Brackets : , , 8 , , 8 8 &3 , 8
se of T. (Brackets,

( .: ( ( - , 8 2 ( , 8 ( , 8 , 8@


, 8-
se of T. (Brackets , 8 Y, 8 , 84 Tk , , 8 , 8 , 84 , 8 , 8 (
se of T. (Brackets) X4 ( , 8 , 8-
se of T. (Brackets , 8 , 8 (
, 84 3 , 4 (
se of T. (Brackets 8 , 8, 8 ( - ( , 84 , 8 :) 4 ( (

se of T. (Brackets) X4 ( , 84 , 8 , 8 :

>>> def movetriangle(event):


... canvas.move(1, 5, 0)

, 8
se of T. (Brackets) , 8 ( , 8& ( (, 8-
se of T. (Brackets ) , 84 3, 8 Tk , 8& ( &3 , 8 ( 3, 8, 8@ 4

se of T. (Brackets) , 8 , 8 & - , 8, bind_all


se of T. (Brackets) &3 , 8 Tk- , 84 , 8 , 8 ( ( ( 2r
, 8-, 8
se of T. (Brackets :)
se of T. (Brackets) &4 3, 8 , ( 3, 8 :

>>> from tkinter import *


>>> tk = Tk()
>>> canvas = Canvas(tk, width=400, height=400)
>>> canvas.pack()
>>> canvas.create_polygon(10, 10, 10, 60, 50, 35)
>>> def movetriangle(event):
... canvas.move(1, 5, 0)
...
>>> canvas.bind_all(<KeyPress-Return>, movetriangle)


bind_all
se of T. (Brackets) , 8 , 8& ( , 8-
se of T. (Brackets ( F 4 2 , 8 , 8 , 8 & , 8-
se of T. (Brackets 3, 8
KeyPress-Return ( , 8 3, 8F
se of T. (Brackets 8 , ) 2
se of T. (Brackets 8 , , 8-
se of T. (Brackets , ( 4 3, 8
movetriangle
se of T. (Brackets) , 8 , ( , 8 , 84 , 8 , ( , 8 Tk & - , 8, ( , 8
8, 8 , 8,2
se of T. (Brackets ( ( 2) 8 , 8, 8
( - ( - 8 , 8, 8 ( -, 8 ( , 8 ( 42 , 8 3? 3, 84 , 8 , 8 , 8 & 8 3, 8 arrow 8 :)
, 8 ( , 8 ( - [ , 8
se of T. (Brackets) , 8 ( 42 , 8 ( , 84 3, 8:

>>> def movetriangle(event):


... if event.keysym == Up:
... canvas.move(1, 0, -3)
... elif event.keysym == Down:
... canvas.move(1, 0, 3)
... elif event.keysym == Left:
... canvas.move(1, -3, 0)
... else:
... canvas.move(1, 3, 0)
movetriangle , 8-
se of T. (Brackets , 8 , 8 ( @, & properties , 8 , 8 , 8 & ( 3, 8F keysym #
8 ( ( a ( keysym Up ( a , 8 4 3, 8 (1, 0, -3) , 8& ( , 8 canvas.move
( , 8 2 3, 8 ( ( , 8 , 84 3 4 3, 8 , 8& ( 3, 8 (1, 0, 3) , 8 , 84 3, 8 ,
, 8& ( 3, 8F & - , 8, [ 8 H ( 4 / , 8 , & , ( v48 , 8& ( 3, 8F x , 8
(-# ( ) , 84 3, 8 4 , 8& ( ( 3, 8F y , 8 () , 84 3, 8
4 4 3, 8 Tk
se of T. (Brackets) , 8 , 84 , 8 ( movetriangle
se of T. (Brackets) ( ( - , 8 8 (, 8, 8 , ( , 8, , , 8,
, 8) ( , 8 , 8-
se of T. (Brackets , 8 ( , 8 4 3, 8 , 8, 3 3, 8:

>>> from tkinter import *


>>> tk = Tk()
>>> canvas = Canvas(tk, width=400, height=400)
>>> canvas.pack()
>>> canvas.create_polygon(10, 10, 10, 60, 50, 35)
1
>>> def movetriangle(event):
if event.keysym == Up:
canvas.move(1, 0, -3)
... elif event.keysym == Down:
canvas.move(1, 0, 3)
elif event.keysym == Left:
canvas.move(1, -3, 0)
else:
... canvas.move(1, 3, 0)
...
>>> canvas.bind_all(<KeyPress-Up>, movetriangle)
>>> canvas.bind_all(<KeyPress-Down>, movetriangle)
>>> canvas.bind_all(<KeyPress-Left>, movetriangle)
>>> canvas.bind_all(<KeyPress-Right>, movetriangle)
4 ( - arrow 8 , 8, 8 4 ( , 8 2 8 , 8

Properties 3, 8F ( @ 2 8 , , 8 X ( r& , 84 , 8 , 8 : , 8 2 3 8 ( , 8
( , 8 , 84 , 8 ( , 8@ ( ( Properties , 8 ( &


&

, 8

4! , 8, 8 4 ( X4 ( , 84 , 8, 8 @

, 8 4 ( , , 8 8 ( , 84 , 8, 8 , 8@ ? , 8 3 ( @ , 4 , 8 :) :)
( ( ( , 84 , 3 4 , 8 , 8 ( ( ( - , 4, 8 ( 4 ( , 8 :) (
( ( - , , - , 8 3, 8 4 ( , ( ( :) , 8 , 8 4 ( , 84 , 8 , 8
, 8 , 8 - , 8 ( @ , 8 , 8 28- , 8 X4 ( 3, 8, 8@

, 4 ( ( , :) ( ( , 84 4, 8 BlitzBasic (www.blitzbasic.com) , 84


, 8 , , 84 , 8 , 8 , , 8 ( , ( ( - &3 3, 8, 8@ & , 84
, 8 , 8 ( , 8 , 8 , , 8 & ( , 8 ( , :) &3 3, - Nickelodeon
, 8, , www.nick.com, , 8 X & &3 3, 8, 8@)

4 ( ( & ( ( , (38 3 4, 8 ( :) , , 8, 8 - , 8 3, 8 Andy Harris
Beginning Flash Games Programming for Dummies ( 4 ( ( ( , 84
4, 8 Serge Melnikov The Flash 8 Game Developing Handbook ( , 8 , 84 , 8 , 8 4 ( (
, 8, 8 & , , , 8 2 , 84 4, 8 www.amazon.com ( W , , , 8 2 , & , 8 , 8

@ ( @ ( ( 3, 8 : Jonathon S Harbour Beginners Guide to DarkBASIC


Game Programming ( ( , 84 ( , ( ( - &3 3, 8, 8@ Maneesh Sethi Game
Programming for Teens ( ( , 84 BlitzBasic &3 3, 8, 8@) ( , 8 , 84 3, 8 ,
BlitzBasic, DarkBasic and Flash ( 4 ( , 8 ( , 8 ( , 84 3, 8 ( 2 , 8 , 8 , 84 (
) 4 ( ( - , 8 &3 , 84 , 8 - , 8 , 84 3, 8

4 ( ( X4 ( ( ( - ( 3, , 8 , 8 , 8 @ , 8 , 8 4, 8 www.pygame.org


, 8 , ( Sean Riley Game Programming With Python ( , , 8 , 8
, 84 , 8 , 8

4 ( ( ( W , 84 , 8 , 8 ( :) ( ( - ( , 8 , ( 4 ( ( , 8 , , , 8 2


, 8 ( , 84 4, 8 Mark Pilgrim Dive into Python ( , 84 , 8 , 8
(www.diveintopython.org ( , 8 , 8 , 8) @ http://docs.python.org/tut/tut.html , ( , 84
X ( ( , 8 ( 4 ( , 84 , 8 , 8 , 8 ( @ , 8@ ( , 84 ( ( 4 , 8
( ( , 4 ( , ( , 84 ( , 8 , 8 , , , 8 2 ( ( 4- , 8 , 84 , 8 , 8 , 8 , 8 , , 8 , 84
, 8 , 8

Good luck and enjoy your programming efforts.


4 :) - , 8 ( 4 ( 4 , 8 ( ( 4 , 8 , 8 , 84 , 8 , 8
8


, 8 ( ( r A

, 8 , 8 # , #3

:) :) ( , 8 , 84 , 8 , 8 8 ,2 (key word) , 8#2 -# ( , 8 , 8 , ( , 8 (
- v &3 3, 8 , 8 ( 4 ( 8 ,2, 8 , 8 - ( , 8 :) , 8 , 8 &3
r , 4, 8 , 8 , 8, , 8 ? , 8 ( (error) , H 42 , 84 , 8 , 8 ( , 8 , 8
8 ,2, 8 ( 2 3, 8

and
( , 8
se of T. (Brackets ( , 8 ( 4 , 84 and &3 3 ( , 8 if , 8
se of T. (Brackets
, 84 ), v 3 , 8
se of T. (Brackets , 8 true 3 , 8-

if age > 10 and age < 20

v , 84 , 8 ( @ , , 8 , 8 @ 3, 8

as
, 8, 8 , 8 2, ( , , 8 :) ( , 84 as 8 ,2 ( &3 3 3 , 8-
( ( , 8 3 , 8 , 84 , 3 , 8 ( ( , , 8

i_am_a_python_module_that_is_not_very_useful

( 4 ( ( 4 ( ,, 8 , 8 , 84 4, 8 4 4 :) ( ( 3, 8 ,

>>> import i_am_a_python_module_that_is_not_very_useful


>>>
>>>
i_am_a_python_module_that_is_not_very_useful.do_something()
I have done something
>>>
i_am_a_python_module_that_is_not_very_useful.do_something_else()
I have done something else!

4 ( ( , 8, 8 2 , 8 4 ( 4 ( , 84 , 8 , 8 , :) ( 4 ( , 8 , 8


( ( , 8 , , 8 , 84 ):

>>> import i_am_a_python_module_that_is_not_very_useful as


notuseful
>>>
>>> notuseful.do_something()
I have done something
>>> notuseful.do_something_else()
I have done something else!


( 4 ( , 4 as 8 ,2 , 8 ( &3 , 84 , 8

assert
Assert ( & ,- 8 ,2 ( @ , , ( 4& ( , 84 Assert &3 3 (
, 8, ( , Y, 8 ( , 8 , 4 ! , 8 2 , 8 ( , 8 ( &3 3

break
, 8, , 8 :) break &3 3 4 ( for-loop -4, 8 break ( , 8 , 84 , 8
&3 , 84 , 8 , 8 :

>>> age = 25
>>> for x in range(1, 100):
... print(counting %s % x)
... if x == age:
... print(end counting)
... break

( ( - ( , 8 'age' :) ( 2 ( 4, 8 ( , 8 , , 8:

counting 1
counting 2
counting 3
counting 4
counting 5
counting 6
counting 7
counting 8
counting 9
counting 10
end counting

for-loop , , , 8 2 , 8 :) , 8 & , 8 ( , 8

class
( , 8 , 8 type ( 2 , 84 class 8 ,2 ( &3 3 , 8 ( ( & , 8, 8
:) ( ( X ( r& ( ( 3 4 ( , 8 , 3 4 , 8 , 8
( , 8 :) ( & ,- 8 ,2

del
( @ 3 4 , 8 ( , 8 :) del ( , 8#2 8 ,2 3 , 8 , 8 , 8 , 4 ( 4
( , 8 ( ( 4 ( 4 ( , , 8 ( , 84 ( , 8 , 8 , 8@ ( , 8 ( , 8 4 , 8
, 8 ( 42 3 ( , 8 ( ( , 8 , 8 ( 4 ( , 8 , 84
( , 8 , 8
se of T. (Brackets (
4 , , 8
( ,
( - ( ,


4 ( ( ( , 8 , 8 ( ( 4 3, 8 4 , 3, 8-

>>> what_i_want = [remote controlled car, new bike,


computer game]

( , , 8 ( , 8 ( 4 , 8 , 84 4, 8 , ( , 84 3, 8 4


3 :
>>> del what_i_want[2]
>>> what_i_want.append(video game)

( 4 4 ( , 84 , 8 , 8 :

>>> print(what_i_want)
[remote controlled car, new bike, video game]

( v48 & , 8 ( , 8 ( ( 4 , 8 , 8

elif
if-statement ( ( 3, 8, , 8 ( &3 3 if , 8 , 8 ( , 84 3, 8...

else
( if-statement ( 3, , 8 &3 3 if , 8 , 8 ( , 84 3, 8...

except
, 8, ( ( 2, 8 :) :) ( 8 ,2 except &3 3 ( &3 3 (
( , 8 , 84, 4 , 8 :) ( ( & ,- 8 ,2

exec
( exec , 8 , 8, ( , ( &4 3 ( , 8
se of T. (Brackets) ( 3, 8, , 8 , 8 ( a - , 84
3 , 8 4 ( ( , 8 , 84 , 8 ( a , 3 ( - ( , 8 X4 ( , 84 , 8 :

>>> myvar = hello there

4, 8 (
se of T. (Brackets
se of T. (Brackets, ( , 8 , 8 :

>>> print(myvar)
hello there

( a , 8 ( , 842 ( 4 ( ( @ , 8 , &3 , 84 , 8 , :

>>> myvar = print("hello there")

, 8 4 ( ( exec &3 , 84 , 8 , ( a ( , 8 ( @ , 8 ( , 8 , 8 ( 4 , 8


4 , 8:

>>> exec(myvar)
hello there

( ( , 8 ( 2 ( @ , , , 8 2 X4 ( ( 4 , 8 2 , 8 4


&3 , 8 , 8, 8 exec- , 8 assert , 84 ( & ,- 8 ,2, , 8
( ( , 8 &3 3

finally
( , 8 ( & ,- 8 ,2 3 4 ( @ ( , 8 , , 8 4 :)
8 ,2 &3 3 (, 4 ( , 8@, 8 , 8 'mess' # , 84 ( &3
3)

for
for 8 ,2 ( &3 3 ( for-loop X4 ( , 84 3 , 8;

for x in range(0,5):
print(x is %s % x)

, 8, 8 for-loop ( , 8 Y , ( , 8 , 8 ( ( 4 , 8


se of T. (Brackets)
se of T. (Brackets) X4 ( , 8 ;

x is 0
x is 1
x is 2
x is 3
x is 4

from
( ( , , 8, 8 2 3, 4 from 8 ,2 &3 , 8 &, 8 , 8, 8 ( , , 8, 8 2 , 8
, 8 8 ( , 8, 8 2 , 84 , 8 ( 3 , 8, turtle ( ,, 8 (
se of T. (Brackets) Pen()
&3 3, 8, 8@ ( , 8 , 8 X4 ( , 84 (# 4 ( ( & - , , 8 turtle ( , 8 )
4 ( ( , 8 , 84 , 8 turtle ( , , 8, 8 2 , 8 pen
se of T. (Brackets) &3 , 84 , 8

>>> import turtle


>>> t = turtle.Pen()

4 ( , 8 , , ( pen
se of T. (Brackets) &3 , 84 , 8 , 8 (turtle ( , , 8
se of T. (Brackets) , 8 (
&3 )

>>> from turtle import Pen


>>> t = Pen()

2 4 ( ( , , 8, 8 2 , 8 , ( , - &3 , 84 , 8 , 8 3 , 8


, time ( ,, 8 (
se of T. (Brackets) localtime gmtime ( localtime , 8, 8 2 (


gmtime &3 r ( 4, 8 ( , 8 , 8 :

>>> from time import localtime


>>> print(localtime())
(2007, 1, 30, 20, 53, 42, 1, 30, 0)

, 8 ( ( , ( ( ( 4, 8 4 , 8 :

>>> print(gmtime())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Name : name gmtime is not defined

, 834 gmtime ( ( 2r , 8 ( 4 , 8 , 8 , 8 gmtime


se of T. (Brackets) (
, 8 4, 8 F
se of T. (Brackets) ( ( ,, 8 -4, 8 &3 ( 4 , 8 ( ( ,
( , 8
se of T. (Brackets) , 84 4, 8 ( asterisk (*): &3 , 8 ( , , 8 , 8, 8 2 , 84 , 8 ( :

>>> from time import *


>>> print(localtime())
(2007, 1, 30, 20, 57, 7, 1, 30, 0)
>>> print(gmtime())
(2007, 1, 30, 13, 57, 9, 1, 30, 0)

, 8, 8 time ( , , 8 , ( @ , 8, 8 2 , 84 , 8 , 8 , 8

se of T. (Brackets) , 8


se of T. (Brackets) , 84 , 8 , 8

global
& , 8 scope ( , 8 , 8 , 8 ( @ scope 3 ( - ( , 8, 8 H 4 visibility (
( - ( , 8 , 8
se of T. (Brackets) , 8 , 8 ( 4 3, 8 , 4 (
se of T. (Brackets) , 8 -4, 8 , 8 (
(
se of T. (Brackets) , 8 -4, 8 ( 4 3, 8 ( 4
se of T. (Brackets) , 8 , 8
global - ( , 8 ( , 8 & ( 4m ( 3, , 8 &3 3 ( ( - ( , 8 , 8 global
( 3, 8, , 8 ( 4, 8 4 , 4 global - ( , 8 , 8 , 8H ( 8& , 88
, 2 8 - ( , 8 , 84 , 8 ( ( , 8 , 8 , 8, , 8 ( @ , 8H ( 8 - ( 4, 8
global - ( , 8 , , 8H ( 8& ( , 8 ( H ( 4 , 8 3 , 8:
>>> def test():
...
global a
...
a = 1
...
b = 2

( , 8 3, ( , 8 print(a)


se of T. (Brackets, , 8, 8 print(b)
se of T. (Brackets, 4, 8 ( 3, 8 ? (
se of T. (Brackets)
( 4, 8 , 84 , 8 , ( , 8@ ( , 8, 8 ( ( , 8F


>>> test()
>>> print(a)
1
>>> print(b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Name error: name b is not defined

, 8 a - ( , 8 ( global, ( b - ( , 8 (


se of T. (Brackets) , 8 -4, 8 , 8F , 8 , 8
- ( , 8 , , 8 4 , 8 global ( 3, 8, , 8 ( , 84 3, 8, 4 , 8

if
( @ , , , 8 2 ( , ( , 84 if &3 3, ( ( , 8
se of T. (Brackets ( , 8 , additional 8 ,2
else elif (else if) , , 8 &3 3 , 8
se of T. (Brackets ( '' ( ( ( , ( 4& 3 4, 8 , (
( ( 2r , 8'' , 8 :) &3 3 3 , 8:

if toy_price > 1000:


print(That toy is over-priced)
elif toy_price > 100:
print(That toy is expensive)
else:
print(I would like that toy)

3 , 8 , 8F, , 8 if , 8


se of T. (Brackets , 8@ ( 3 ( 3 4, 8 4
( 4 ( ( , ( , 8 Y , 8, 8 3 4, 8 4 8, :) ( , 84 , 8@, '' (
, 8@J ( '' 4 2 & , 8 ( , 8 , 8 ( 3 , 8@

import
, 8 , 8 :) ( , , :) import 8 ,2 &3 3 3 , 8:

>>> import sys

, ( , 8 , 8 , 8 'sys' ( , &3 , 84

in
in 8 ,2 ( &3 3 , 8 , 8 , ( , 8 , 8 , 8 ( ( ( 2r , 8 , 8@ ( 4
Y, 8 , 84 ( &3 3 3 , 8, ( , 8 4 ( (, H384) , 8 1 Y, 8
, 84 , 8 ( :

>>> if 1 in [1,2,3,4]:
... print(number is in list)
number is in list
( , 8 ( , 8 , Y, 8 , 8, 84 , 8 ( :

>>> shopping_list = [ eggs, milk, cheese ]


>>> if lettuce in shopping_list:
... print(lettuce is in the shopping list)


... else:
... print(lettuce is not in the shopping list)

...
lettuce is not in the shopping list

is
is 8 ,2, , 8 , 8 , 8 (=) , 84 , ( , 4 , 84 &3 3 ( 3 , 8
10==10 , 10==11
se of T. (Brackets) , ) 3 is == , 8 ( q ( , 8 2 & , 8@ 4 ( ( (
( ( , 8, , 8 4 , 8 , == ( 2 , 8, , 8 is , , 84 , 8 , 8 ( ( 4 ( , 84
, 8 , 8 ( ( , , 8 , )

, 8 ! 4 ( ( (
se of T. (Brackets) , 8
se of T. (Brackets) , 8 , , , 8 == &3

lambda
( ( & ,- 8 ,2 , , 8 ( ( ( , , , 8 2 , 8 , 84 4, 8
, 8 , 8 ( ( , 8 , 8 , 8 , 8

4 , 8 , , , 8 2 , 8 -

not
( , 8
se of T. (Brackets , ( 4& 3, 4, 8 not 8 ,2 , 8 ( & , 84 , 8 , 8 ( ( - ( , 8 x
X4 ( ( ( 2 ( true...

>>> x = True

... ( x not &3 , 8 (


se of T. (Brackets ( 4 3, 8 , 8 , 8 4 3 :

>>> print(not x)
False

if-statements- &3 , 8#2 , 8 2 ( ,2 ( 3


3 , 8, ( 4 , @ 3 @ 4 :) , 8#2 ( @ 3
4 ( @ , 8
se of T. (Brackets) , 84 , 4 3, 8 4 ( ( , 8:

1 is not an important age 2 is not an important age 3 is


not an important age 4 is not an important age ... ... 50
is not an important age

- , 8 , 8 ,
if-statements 42 , , 8 ( , 84 , 8 ( ...

if age == 1:
print("1 is not an important age")
elif age == 2:


print("2 is not an important age")
elif age == 3:
print("3 is not an important age")
elif age == 4:
print("4 is not an important age")

- , 8 , 84 , 8...4, 8 ( ( , , 8 , 8@:

if age < 10 or age > 10:


print("%s is not an important age" % age)

( , 8 , 3 ( , 8 3, 8 , not v if-statements &3 :

if not age == 10:


print("%s is not an important age" % age)

4, 8 4 ( 3, 84 , 84 , 8, 8 , 8@ , if age is not 10 , 8 ( , 3 , 8

or
( a , 8, 8
se of T. (Brackets -4, 8 ( , 8 , 8 :) or 8 ,2 ( &3 3(, 8 if-
statements , 84 ) v 3 , 8 ( , 8 , ( 4& 3 , 8:

>>> if friend == Rasel or friend == Robi:


...
print(The Robin)
... elif friend == Belal or friend == Bobi:
...
print(The Babita)

, 8, ( - ( , 8 , 8, ( ( Y, 8 , 8 4 3, 8 The Robin (


se of T. (Brackets , 8 ( - ( , 8
( Y, 8 , 8 4, 8 'The Babita' (
se of T. (Brackets , 8

pass
, 8 , 4 ( ( ( ( , 8 4 4 ( ( , 8 ( , 8 , 8
se of T. (Brackets)
se of T. (Brackets) , 84
r , 8 , 4 3, 8 4 ( ( if-Statement ( , 8 ( 4 , , 8
se of T. (Brackets)
se of T. (Brackets)
, 84 r , 8 4 ( for-loop , 8 , 8 ( 'for-loop'- , , 8

>>> if age > 10:


... print(older than 10)

, ( , 8, ( 4 ( ( , 8 :

>>> if age > 10:


...


4 3, 8 4 ( ( , 8 , 84 , 8 , 8 , 8, , 8 ( , 8, , 84 , 8 , 8 :

File "<stdin>", line 2


^
Indentation error: expected an indented block

4 ( ( , :) 48 , 8
se of T. (Brackets ( , 8 4, 8 , 8 48 , 8, ( , 8
pass 8 ,2 , 8 &3 3, , 84 4 ( ( , 8
se of T. (Brackets ( , 84 , 8 , ( ( , ( , 8
, 8 4, 8 ( , 8 3 , 8, 4 ( ( , 8 , ( , 8 4 , 84 4 ( for-loop
&3 , 8 ( , 8 if-statement -4, 8 ( 4 ( ( W , if-statement (
, 8 4 ( 3, 84 print , 84 , 8 , 8 break , 84 , 8 , 8 :) ( @ , 84 , 8 , 8 ,
, 8 4 ( pass 8 ,2 &3 , 84 , 8 , 8 4 , ( , 8 ( ( 4 ( ( , 84 , 8@
4 3, 84 , 8 , 8 ) , ( 3 :

>>> for x in range(1,7):


... print(x is %s % x)
... if x == 5:
... pass

se of T. (Brackets)


se of T. (Brackets) ( 3, , 8 , 8 , 8:

x is 1
x is 2
x is 3
x is 4
x is 5
x is 6

, 8 428, 84 4 ( pass , 8 if-statement , ( , , 84 , 8 , 8

print
print 8 ,2 , 8 , 8, , 8 ( a , ( - ( , 8 ( , 8 , 8 :

print(hello there)
print(10)
print(x)

raise
( ( & ,- 8 ,2 , 8, 8 raise &3 3 ( , ( W4 3 ( 3, , 8
, 8 3 ? 4 , 4, 8 & ,- ( , 8 ( 8 ( 8 ,2

return
return 8 ,2 &3 3
se of T. (Brackets) , 8 (
se of T. (Brackets) ( , 8 :) 3 , 8, 4 ( (

se of T. (Brackets) X4 ( , 84 , 8 , 8 4 ( , 8 ( @, 8 4 , 8 ( @
se of T. (Brackets) 4 :


>>> def mymoney():
... return money_amount

4 (
se of T. (Brackets) , 8 , 8 4 ( :) ( - ( & , 8
se of T. (Brackets) 4 ( , 8

>>> money = mymoney()

(
se of T. (Brackets , 84 , 8 , 8 ,

>>> print(mymoney())

try
try 8 ,2 ( , 8, 3 except / finally 8 ,2 v , ( @
, , 8 2 try/except/finally &3 3 ( ( , 8 , 8, ( :)
3 , 8, ( &3 8 :) ( , 8 8 , 8, 2 , 8 ( , 8
, 8 - [, 8

while
( for-loop , 84 while 3, 8F ( , 8 , 8, :) ( , 8 , 8 for-loop , ( , 8
, 8 2
se of T. (Brackets , 8 , , 8 while ( , 8 , 4& 3 , 8 2 , 84 , 8 4 4 , 8 while &3
, , 4 2 , 84 3, 8 ( , 8 ( , , , 4& 3 4, 8 while , , , 84
, 8, 3, 8 ( , 8 , 8 38 , 8 3) 3 , 8:

>>> x = 1
>>> while x == 1:
... print(hello)

( 4 ( , 8, 8 , ( 4, 8 4 ( ( , 8 :) , 84 , 8 , 4 4 ( , 8 , 8,


, 8 CTRL+C , 8, 8 ( , 8 control 8 C 8) ( , 8 , 84 , 8 , 8 , 83 while
, ( ( , 8:

>>> x = 1
>>> while x < 10:
... print(hello)
... x = x + 1

( 4 ( hello (
se of T. (Brackets , 84 ( ( 4 x , 8 , , 8 1 3, 8 4 x, 10 , 8
3) ( ( for-loop , 84 , ( ( ( ( ( 2r [ , 8

with
( ( & ,- 8 ,2

yield
( , 8 ( & ,- 8 ,2


, 8 ( ( r B

, 8#2 ( 2 ( 4
se of T. (Brackets) , 8

, 8 , 8 , 8 , 8#2 ( 2 ( 4


se of T. (Brackets) , 8@-
se of T. (Brackets) , 8 &3 , 8#, 82 , 8, 8 2 , 8
( , 8 ( @ , 8#2 ( 2 ( 4
se of T. (Brackets) , 8 2 3

abs
abs
se of T. (Brackets) ( , 8 , 8 , 8 ( 3, , 8 ( 2 , 8 , 8 3, 8 ,
, 84 , 8 ( , 8 -. , 8 . 3 , 8 , 84
, 8 , 8 :

>>> print(abs(10))
10
>>> print(abs(-20.5))
20.5

bool
, 8& ( , 8 , 8 , 8 ( - ( , 8 bool
se of T. (Brackets) true false ( 2 , 8 , 8 :) 0 ( 2
, 8 false ( 3, 8, , 8, , 8 :) true ( 3, 8, , 8 ( 2 , 8

>>> print(bool(0))
False
>>> print(bool(1))
True
>>> print(bool(1123.23))
True
>>> print(bool(-500))
True

:) , 8 :), 4 ( @ true 3 44 ( @, 8 false ( 3, , 8 ( 2 , 8

>>> print(bool(None))
False
>>> print(bool(a))
True

cmp
( ( , 8 , 8 ( ( v48 ( , 8 4 # - , 8 @ 3 4, 8 cmp
se of T. (Brackets) ( 2
, 8 ( ( ( v48 ( , 3 4, 8 0 ( 2 , 8 ( ( ( v48 ( , 8 3 4, 8
( 2 , 8 3 , 8:
, 8 @ 3 4, 8:

>>> print(cmp(1,2))
-1


( , 3 4, 8:

>>> print(cmp(2,2))
0

( , 8 3 4, 8:

>>> print(cmp(2,1))
1

4 , & , , 8 3, 8 4 , :) :) ( a , 8 3, 84 , 8 , 8 :

>>> print(cmp(a,b))
-1
>>> print(cmp(a,a))
0
>>> print(cmp(b,a))
1

( ( a ( , 8 , , 4 , 84 3, 8 , , 8 , ( 2 4 ( , 8


4 , 84 3, 84 , 8 , 8 ...

>>> print(cmp(a,A))
1
>>> print(cmp(A,a))
-1

@ 3 , 84 a , , 8 3 , 84 3


se of T. (Brackets) A , 8 , ...

>>> print(cmp(aaa,aaaa))
-1
>>> print(cmp(aaaa,aaa))
1

... ( 4 , 8 a (aaa) , 8 a (aaaa) , 8 @

dir
( , , , 8 2 48 4 & dir
se of T. (Brackets) ( 2 , 8 4 ( dir
se of T. (Brackets) ( &3 , 84 , 8 , 8 , 8 ( a ,
,
se of T. (Brackets) , ( , , , 8 , - , 8 ( @ , 8 , 8 4 & 8 3, 84 , 8 , 8
( H4 , 8, 8 , 8 ( @ ) 3 , 8,
se of T. (Brackets)
se of T. (Brackets) , 8 :) ( dir
se of T. (Brackets)
( 4 3, 8 , 8 , 8 ......

>>> dir(1)
[__abs__, __add__, __and__, __class__, __cmp__,
__coerce__, __delattr__,
__div__, __divmod__, __doc__, __float__, __floordiv__,
__getattribute__,


__getnewargs__, __hash__, __hex__, __index__, __init__,
__int__, __invert__,
__long__, __lshift__, __mod__, __mul__, __neg__,
__new__, __nonzero__,
__oct__, __or__, __pos__, __pow__, __radd__, __rand__,
__rdiv__,
__rdivmod__, __reduce__, __reduce_ex__, __repr__,
__rfloordiv__,
__rlshift__, __rmod__, __rmul__, __ror__, __rpow__,
__rrshift__, __rshift__,
__rsub__, __rtruediv__, __rxor__, __setattr__, __str__,
__sub__, __truediv__,
__xor__]

( , 8
se of T. (Brackets) ( , 8 ( a
se of T. (Brackets) , 8 :) dir ( ( 4, 8 ( 3, , 8 , 8 , 8 ......

>>> dir(a)
[__add__, __class__, __contains__, __delattr__, __doc__,
__eq__, __ge__,
__getattribute__, __getitem__, __getnewargs__,
__getslice__, __gt__, __hash__,
__init__, __le__, __len__, __lt__, __mod__, __mul__,
__ne__, __new__,
__reduce__, __reduce_ex__, __repr__, __rmod__, __rmul__,
__setattr__,
__str__, capitalize, center, count, decode, encode,
endswith, expandtabs,
find, index, isalnum, isalpha, isdigit, islower,
isspace, istitle,
isupper, join, ljust, lower, lstrip, partition,
replace, rfind, rindex,
rjust, rpartition, rsplit, rstrip, split, splitlines,
startswith, strip,
swapcase, title, translate, upper, zfill]

se of T. (Brackets) ( 3 , 8


se of T. (Brackets) 3 4, 8 , 84 , 8 , ( ( a 3
se of T. (Brackets) , 8 ( 42 , 8 3 , 84
)......

>>> print(aaaaa.capitalize())
Aaaaa

...isalnum ( ( ( ( a &
se of T. (Brackets) ( , 8 ( 3 4, 8 true ( 2 , 8 -
, 8 ), isalpha ( ( ( ( a , 8 4, 8 true ( 2 , 8 ) ( @ 4
( - ( , 8 , 8 4 ( , 84 4 4 Y, 8 , 84 4 3, 8 dir , 8 ( 3, 84
, 8 , 8


eval
eval
se of T. (Brackets) , 8 , 8& ( ( 3, , 8 (3 , 8 , 8 - , 8 , 8 , 8 3 ( ( , 8
, 8 ( , 8 exec 8 ,2 , 84 , ( , 8 ( @ ( - , 8 , 8 exec ( , 8 4 ( (
( a -4 @ , 8 ( X4 ( , 84 , 8 , 8 ( eval 4 , 8 , , 8
( 3, , 8 ( 4 ( , 8, :

>>> eval(10*5)
50

file

se of T. (Brackets) ( (
se of T. (Brackets) X4 ( -4, 8 , 8 , 8 ( 2
se of T. (Brackets) , 8 -4, 8 4 &, 8 , 84
(
se of T. (Brackets) , 8 , 8
se of T. (Brackets , ( @, 84) , 8, 8, ( 4 4 (
se of T. (Brackets)
se of T. (Brackets) , 8 , , , 8 2
, & , 8 ( ( 4 , 84 , 8 , 8

float
float
se of T. (Brackets) ( ( a - ( floating point- , 8 , 8 , 8 ( floating point
3, 8 ( ( [ , 3 , 8 , 8 ( , ( 4& , 8 3

3 , 8, 10 3 ( integer ( ( , 8, 8 ( 3, 8, , 8 3) ( , 8 10.0, 10.1,


10.253, , 8 , 8 , , 8 ( , & (floats) 3 4 ( ( ( a - floating , 8 ( 4
, 84 , 8 , 8 - , 8:

>>> float(12)
12.0

4 ( ( ( a - -4, 8 - , 8 ( [ &3 , 84 , 8 , 8 :

>>> float(123.456789)
123.456789

4 ( - , 8 ( , 8 float , 84 , 8 , 8 :

>>> float(200)
200.0

4 ( ( floating , 8 ( floating point , 8 ( 4 , 84 , 8 , 8 :

>>> float(100.123)
100.123

4 ( ( float- 4, 8 , 8 , 8 0.0.

int
int
se of T. (Brackets) ( ( ( a , 8 ( , 8, 8 , 8 , 8 , 8 ( integer)
3 , 8:


>>> int(123.456)
123
>>> int(123)
123

( , 8 float
se of T. (Brackets) , 8 , 84 , 8 , 8 4 ( ( ( floating point , 8 ( a -
, 8 , 84 4, 8 ( 42 , 8:

>>> int(123.456)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 123.456

3 , 4 ( ( ( int 2, 8
se of T. (Brackets @ , , 8 4, 8 4 ( 0
se of T. (Brackets) 4 , 8 , 8

len
len
se of T. (Brackets) ( , 8 , 8 length- ( 2 , 8 ( ( a , 8 ( ( a , 8 , 8 ( 2
, 8

>>> len(this is a test string)


21

4 ( , 8, 8 (tuple) , 8 ( , 8 , 8 ( 2 , 8 :

>>> mylist = [ a, b, c, d ]
>>> print(len(mylist))
4
>>> mytuple = (1,2,3,4,5,6)
>>> print(len(mytuple))
6

( & , 8, 8 , 8 ( , 2 4 ( ( 2 , 8 :

>>> mymap = { a : 100, b : 200, c : 300 }


>>> print(len(mymap))
3

4 ( len
se of T. (Brackets) ( , , 8, 8 ( &3 , 8 , 8 loops , 8 4 ( ( ( 4 ( , 8 , 8
, 84 4 3, 8 ( , 8 , ( &3 , 84 , 8 , 8 :

>>> mylist = [ a, b, c, d ]
>>> for item in mylist:
... print(item)

4 ( (a, b, c, d) , , 8 , 8 (


se of T. (Brackets , 8 , 8 - ( 4 ( ( 4 ( ( 4 ( , 8 , 8 , # (
, 84 , 8 4, 8 ( 3, 8 ? , 8 4 ( length , 84 , 8 ( , , 8 4 (
, 84 , 8 (


>>> mylist = [ a, b, c, d ]
>>> length = len(mylist)
>>> for x in range(0, length):
... print(the item at index %s is %s % (x, mylist[x]))
...
the item at index 0 is a
the item at index 1 is b
the item at index 2 is c
the item at index 3 is d

4 ( length ( - ( , 8 length v , , 84 , 8 ( - ( , 8 (


, 8 , 8 X4 ( ,
se of T. (Brackets) , 8 &3 , 84 , 8 (

max
( 4 ( , , 8, 8 ( ( ( a , 8 , , 82 ! , 8 ( 2 , 8 max
se of T. (Brackets) 3 , 8:

>>> mylist = [ 5, 4, 10, 30, 22 ]


>>> print(max(mylist))
30

( ( a , 8 , 8 , 8 ( v , 8H , 8 ( [ v , 8H , 8 4, 8 ( , 8 :

>>> s = a,b,d,h,g
>>> print(max(s))
h

4 ( ( 4 ( , 8 ( a , 8 , 4 , 8


se of T. (Brackets) , 8 -4, 8 , , ( max &3
, 8 , 8 2, 8
se of T. (Brackets , 8 , 84 , 8 , 8

>>> print(max(10, 300, 450, 50, 90))


450

min
max , 84 - , 8 min
se of T. (Brackets) ( , 8 , 8 4, 8 ( 4 ( / , 8 / ( a , 8 , , 8, 8 @ (
( 2 , 8

>>> mylist = [ 5, 4, 10, 30, 22 ]


>>> print(min(mylist))
4

range

se of T. (Brackets) ( 4 for-loop , 8 &3 3, ( , 8 ( @ , 8 ,, 3 , 8 H
3 , 2 , 8 & , 8 range ( , 8 , 8 , 8 ( @, 4 , 8 ( @ ( , 8 ( ( 2, 8
se of T. (Brackets
&3 3 ( ( ( 4 ( 2, 8, 8
se of T. (Brackets &3 ( , 8 2, 8, 8
se of T. (Brackets ( @ 3
3 :
>>> for x in range(0, 5):
...


print(x)
...
0
1
2
3
4

4 ( 3, 84 , 84 , 8 , 8 ,


se of T. (Brackets) , ( 4& , 8 , 8 2 , 8 , 8 ( 2 , 8 (, 8
iterator , 8 )
se of T. (Brackets) - , 8, 8 &, 8 , 8 4 ( , 8 ( (iterator) 4 ( , 8 , 84 , 8 , 8
( , 8 r ( ( , , 8, 8 (
se of T. (Brackets) &3 ) 4 4 ( ( , 8 , 8 , 8 ( 2
(
se of T. (Brackets , 4, 8 -4 , 84 , 8 , 8

>>> print(list(range(0, 5)))


[0, 1, 2, 3, 4]

4 ( ( 4 ( , 8 , 8 - ( , 8 ( 3, 8, , 8 & , 3, 8 ( @ 4 ( , 8 elsewhere


( 3, 8, , 8 &3 3, 8F:

>>> my_list_of_numbers = list(range(0, 30))


>>> print(my_list_of_numbers)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]

, 2 4H48 2, 8
se of T. (Brackets (3 , 8 , 8 , , 8 step 3 ( ( 2, 8
se of T. (Brackets 3, 8 start stop)
( step
se of T. (Brackets) , 8 ( 4 ( 34 3 ( :)- , 8 4 ( start stop , 8) 4 3, 8
, 8#2 ( 2 ( 4- , 8 &3 3, 8 ( ( 3, 8 4 ( step &3 , 8? ( , 8 3 , 8 :

>>> my_list_of_numbers = list(range(0, 30, 2))


>>> print(my_list_of_numbers)
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]
4 ( ( 4 ( , 8#, 82 , 8 , 8 ( , 8@ H3 step &3 , 84 , 8 ( :

>>> mylist = list(range(0, 500, 50))


>>> print(mylist)
[0, 50, 100, 150, 200, 250, 300, 350, 400, 450]
( , 8 , 8 2 ( 4 ( X4 ( , 8 ( ( , 8 , 8 ), ( 4 , 8 H (
, 8

sum
sum
se of T. (Brackets) 4 ( , 8 , 8 ( , , ( 2 , 8 3 , 8:

>>> mylist = list(range(0, 500, 50))


>>> print(mylist)
[0, 50, 100, 150, 200, 250, 300, 350, 400, 450]
>>> print(sum(mylist))
2250


, 8 ( ( r C

, 8 , 8 ( @ ( ,

, , 8 @ sorts , 8 , 8 , 8 ( , , 8, 8@ 4 ( ( , , 8 , , , 8 2 , 84 4, 8
docs.python.org/modindex.html ( W ( , 8 , 8 , 8 ,, 8, 8
se of T. (Brackets , 84 , 8 , 8 , 8
( &4 , 8 ( ( , , , , 8 2 , 8 , 8 4, 8 4 :) ( , 4 2 42 , 4 ( (
, 8 , 8 ,, 8, 8
se of T. (Brackets , 8 , 4, 8 , , 8 4 ( ( ,, 8 ( 82 4 ( , 84 , 8 , 8 ( @ , , 8
(

The random module


4 ( ( , 8 , 8 , 8 , 8 , 8 , 8 2 , & , 8 ( , &
, 84 , 8, 4 3, 8 4 ( , 8 & , ( , ( , 84 , 8 , 8 & ,
se of T. (Brackets) , 8 ( , & , 8
, 8 , 8 428 & , , 8 :) , 8 8 , 8 ( , , 8 ( , & , 8 4, 8
, 84 & , ( ,
se of T. (Brackets) , 8 , 8 , 8 , ( ( ( , 8 ( ( ,
se of T. (Brackets (randint),
, 8, (choice)
se of T. (Brackets) (shue) , 8 :)
se of T. (Brackets) & , , 8 (
& , , 8 4, 8 , 8 ( , 84 , 8 , 8 - , ,
, 8 , 8 ) 3 , 8 :

>>> import random


>>> print(random.randint(1, 100))
58
>>> print(random.randint(100, 1000))
861
>>> print(random.randint(1000, 5000))
3795

( &3 , 8 while loop- , 3 , 8 & ( , 8 , 84 , 8 ( :

import random
import sys
num = random.randint(1, 100)
while True:
print(Guess a number between 1 and 100)
chk = sys.stdin.readline()
i = int(chk)
if i == num:
print(You guessed right)
break
elif i < num:
print(Try higher)
elif i > num:
print(Try lower)

4 ( ( 4 ( , 8 4 ( ( 4 ( , 8 ( & , , 8 4 , 84 4, 8 choice


&3 , 84 , 8 , 8 3 , 8:


>>> import random
>>> list1 = [ a, b, c, d, e, f, g, h ]
>>> print(random.choice(list1))
c
>>> list2 = [ ice cream, pancakes, trifle, pavlova,
sponge ]
>>> print(random.choice(list2))
trifle

, 2, 8, 8 4 ( ( ( ( , 8 4 ( X4 ( , 84 4, 8 shue &3 , 8 ( ,2
se of T. (Brackets)
):

>>> import random


>>> list1 = [ a, b, c, d, e, f, g, h ]
>>> list2 = [ ice cream, pancakes, trifle, pavlova,
sponge ]
>>> random.shuffle(list1)
>>> print(list1)
[h, e, a, b, c, g, f, d]
>>> random.shuffle(list2)
>>> print(list2)
[pancakes, ice cream, sponge, trifle, pavlova]

The sys module


sys ( , , 8#2
se of T. (Brackets) system- , 8 , 8 , 8 ( 8
se of T. (Brackets) sys ( @ , 8 8

se of T. (Brackets) 3 : exit, stdin, stdout, and version

, 8 , 8 , 8, , 8 ( , 8 :) exit


se of T. (Brackets) , 8 ( , 8 3 , 8 4 ( ( , 8 :

>>> import sys


>>> sys.exit()

4 3, 8 , 8 , 8, , 8 , 8 4 ( ( , , 8 2 , 8


se of T. (Brackets, , & ( ( &3 , 8@
4 , 8 ( -2 , 8 ( ( - ( @ , 84 , 8 , 8 - (
se of T. (Brackets) 3, 8 , 8 , 8, , 8
( , 8

Stdin &3 3, 8, 8@ , 8 , 8 [ , 8 ( & ), ( , 8 , 3 & , 8 ( (
&3 , 8 , 8 , 84, 3 , 8 :

>>> import sys


>>> myvar = sys.stdin.readline()
this is a test value
>>> print(myvar)
this is a test value

, 8, , 8 , 8, ( , 8 84 , 8 ( 4 3, 8 Stdout ( @ , 8 ( , 8 ( , 8
se of T. (Brackets , 84 3, ( (
, 8 , 8
se of T. (Brackets) , 8 , 84 4 , 8 , 8 stdout, print , 8 ( , 8 8


>>> import sys
>>> l = sys.stdout.write(this is a test)
this is a test>>>

, 8 >>> prompt , 8F? ( , 4 ( , 8, , 8 , 8 , 8 4 (


write- , 8 ( ( m- , 8 , 8 428 , 8 , 8 , 8, write &3 :) , 8
, 84 3, 8 4 3, 8 :

>>> import sys


>>> l = sys.stdout.write(this is a test\n)
this is a test
>>>

(, 8 , 84 3, 8 , stdout.write & , 8 , 8 , 8 ( 2 , 8 )

\n 3 4 , 8 , , 8 , 8 & , 8 ( 4 ( enter 8 , 8, 8 , 8, 84) , , 8 , 8 & , 8 3, 8 ( ( , 8
& , 8 4 ( ( a ( 3, 8, , 8 &3 , 84 , 8 , 8 4 ( ( , , ( , 8 , 84 , 8 , 8
3 , 8, 4 ( ( , 8 ( 4 , 8 ( a X4 ( , 84 4 :)
se of T. (Brackets , 8, 8
4, 8 4 ( ( , 84 , 8 , 8:

>>> s = test test


File "<stdin>", line 1
s = test test
^
SyntaxError: EOL while scanning single-quoted string

4 ( , 8 ( , 842 ( , 8, 8 & , 8 &3 , 84 , 8 , 8 :

>>> s = test test\ntest

, , 8, 8 version 3 ( , 8 , 8 , , 8 , 8 - , 2 , 8 &[ , 8 :

>>> import sys


>>> print(sys.version)
2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)]

The time module


, 8 , 8 ( , ( ( ,, , 8
se of T. (Brackets) ( , 8 ... 4 , , 8 ( ,, , 8 , 8 4 ( (

se of T. (Brackets) ( , 8 4, 8


se of T. (Brackets)
se of T. (Brackets) ( 3, , 8 4 ( , 8 4 , 84 , 8 , 8 :

>>> import time


>>> print(time.time())
1179918604.34

time()
se of T. (Brackets) v , ( 4& , 8 2 1st January 1970 (00:00:00am , ( W - , 8) , 8 , , 8
se of T. (Brackets,, 3 ( 2 , 8
4 ( 3, 84 ( , 84 , 8 , 8 , 84 8 ( &3 , 8 ( ( 2r , 8 , 8 3 , 8,


4 ( ( ( ( X4 ( , 8 , 84 r , 8 , ( 4 4 , 8 , 4, 8 4 (
,2 , 8 , 84 , 8 , 8 4 ( 4 , 8 4 , 84 , 8 , 8 3 , 8, , 8
, (
se of T. (Brackets , 84 4 , , 8? 4 ( ( , 84 , 3, 8 (
se of T. (Brackets) X4 ( , 84 , 8 , 8 :

>>> def lots_of_numbers(max):


... for x in range(0, max):
... print(x)

4, 8
se of T. (Brackets) , 84 , 8 , 8 :

>>> lots_of_numbers(100000)

( ( , 84 4 , ( , 8 ( @ , 4, 8


se of T. (Brackets) ( , 8 ( 42 , 8 ( , &3
, 84 , 8 ( :

>>> def lots_of_number(max):


... t1 = time.time()
... for x in range(0, max):
... print(x)
... t2 = time.time()
... print(it took %s seconds % (t2-t1))

, 8 ( , 8 , 84 , 8 ( :

>>> lots_of_numbers(100000)
0
1
2
3
.
.
.
99997
99998
99999
it took 6.92557406425 seconds

( - , 8 , 8 ? time()


se of T. (Brackets) , 8 , - ( , 8 t1 :) , , 8 ( @
4, 8 , 8 H ( , 8 , , 8 (
se of T. (Brackets , 8 ( @ , 8 time()
se of T. (Brackets) , 8 ( @
, , 8 - ( , 8, 8 ( 3, , 8 t2 ( 2 , 8 ( @ , 84 , 8 , , 8
se of T. (Brackets, , 8 ( @
, 8 t2 ( t1 (, , 8 , 8
se of T. (Brackets, 1 Jan 1970 , 8 3, 8 H ( , 8 ( F ) , 8 ( ( @ , 4
st

( t1 , 8 t2 4 3, 8 , 8 3 , 84 , 8 , (


se of T. (Brackets

Time ( ,, 8 , 8 , 8 (


se of T. (Brackets) , 8@ : asctime, ctime, local-time, sleep, strftime, and
strptime.

asctime ( , 8 ( 3, 8, , 8 4 ( , 8 ( , 8 (, 8 , 84 3, 8 ( , 8 3, 8 4 (
, 8 ( 42 ) ( ( , 8W, 8 &
se of T. (Brackets) , 82 , 8 , 8 2, 8
se of T. (Brackets @ ( , 8


( 42 , 4 ( , 8W, 8 &
se of T. (Brackets) , 82 2 , 8

>>> import time


>>> print(time.asctime())
Sun May 27 20:11:12 2007

( 2, 8
se of T. (Brackets , 3 ( , 8 , 8 , , 8 , 8 4 ( , , 8 :) , ( W , 3 ( , 8
X4 ( , 84 3, 8 , 8 ( , 8 & , ( t - ( , 8, 8 , 8 &

>>> t = (2007, 5, 27, 10, 30, 48, 6, 0, 0)

, 8 , 8 m 3, 8F @ , , , ( ,


se of T. (Brackets , ( ( , , , 8
se of T. (Brackets,, , , 83 ( ( 3, 8 , , 3, 8
- , 8 ( , 8 2 ) , 2, 8, 8 @, 8 ( ( , , ( - ( 4
(, , ( - 3, 8 , 3, 8 ) , 8, 8 ( asctime ( 4 3, 8 , 8 , 8 :

>>> import time


>>> t = (2007, 5, 27, 10, 30, 48, 6, 0, 0)
>>> print(time.asctime(t))
Sun May 27 10:30:48 2007

( , 8, 8 , , , 84 3, 8 4 ( ( ( - , 8 4, 8 2 ( 38 4 (


, 8:

>>> import time


>>> t = (2007, 5, 27, 10, 30, 48, 0, 0, 0)
>>> print(time.asctime(t))
Mon May 27 10:30:48 2007

'day of the week' ( 3, , 8 ( 2 3, 8 ( @ ( , 8 ( , 842), 4 asctime ( , 8


, 8, 4 ( , , ( , , 8 ( @ ( ctime
se of T. (Brackets) ( , 8 , , 8 , 8
se of T. (Brackets, , 8 ( 42
:) &3 3 3 , 8, , 8 & & , 84 time()
se of T. (Brackets) ( &3
, 8 ( @ :

>>> import time


>>> t = time.time()
>>> print(t)
1180264952.57
>>> print(time.ctime(t))
Sun May 27 23:22:32 2007

se of T. (Brackets) ( ( , ( 3, 8, , 8 4 ( , , 8 ( 2 , 8 ( , 8 ( 3, 8, , 8
&3 , 8 ( @ , ( 3 4 4 2 , 8 :

>>> import time


>>> print(time.localtime())
(2007, 5, 27, 23, 25, 47, 6, 147, 0)

, 8 asctime ( 3, 8, , 8 , 8 , , 84 , 8 ( :


>>> import time
>>> t = time.localtime()
>>> print(time.asctime(t))
Sun May 27 23:27:22 2007

4 ( ( ( , 8 ( ( ( 2r , ( , 8 , 84 4 sleep


se of T. (Brackets) ( , 8
, 8 3 , 8, 4 ( ( ( 4 , , 8 , 8
se of T. (Brackets, ( , 8 (
se of T. (Brackets , 84 4 3, 8 loop &3 , 8
( ,
se of T. (Brackets) 3, 84 , 8 , 8 :

>>> for x in range(1, 61):


...
print(x)
...
1
2
3
4

( , , 8 , , 8 , 8 , 8 2 (


se of T. (Brackets , 8 4 ( ( , 8 , 8 ( 4 ( (
se of T. (Brackets , 8, 8
se of T. (Brackets , 8
, , 8 , 8
se of T. (Brackets, :) 3, 84 4 3, 8 :

>>> for x in range(1, 61):


...
print(x)
...
time.sleep(1)
...

4 3, 8 ( 4 ( , 8 2, 8 , 8 ( , ( ( ( 4 3, 8 ( ( 4 , , 8


se of T. (Brackets,) ( ( , (
3, 84 ( 4, 8 , , 8 3, 84 , 8 , 8 ( ( , , 8 4, 8 4 8 3, 84
, 8 , 8 4 ( 4 2 ( , 8 , 84 , 8 , 8 4 , 8 ( 4 ( , , 8 ( , 8 4 (
( (/) , 8 , 8 , 8 4 ( ( @ , , 8 :) , 8 4 , 8 , 8 :) ( @ , ( 4
4 , 8 , , 8 :) , ) sleep
se of T. (Brackets) , 8, 8 4 , 8 8

strftime
se of T. (Brackets) 4 ( , , 8 ( 24 , 8 , 8 ( 42, 8 , 8 ( 3, , 8 &3 3 strptime
( ( a ( , 84 4 ( /, , 8, 8 , 8 ( 42 , 8 &3 3 , 8 , 8 strftime
( , 4, 8 4 , 8 , 84 3, 8 ( - , 8 asctime &3 , 8 , 8 , 8 ( a , 8 , 8 ( 42 3:

>>> t = (2007, 5, 27, 10, 30, 48, 6, 0, 0)


>>> print(time.asctime(t))
Sun May 27 10:30:48 2007

( , 8 - , 8 ( ( 3, 8 4 ( - , 8 ( a ( 24 3 , - , 8 ( a 2



, 84 , 8 ( 3, 8 4 ( ( 4 ( , 2 , 84 ? ( , 84 , 8 (
strftime
se of T. (Brackets) v :


>>> print(time.strftime(%d %b %Y, t))
27 May 2007

4 ( , 84 , 8 , 8, strftime ( 2, 8


se of T. (Brackets ( , 84 , 8 , 8 : ( date/time
se of T. (Brackets) , 8, 8 ( 2 , 8 ( - , 8
4 ( , 2 , 8) ( v48 ( , 8 time- , 8 %d %b %Y
se of T. (Brackets) , 8 v
, , 8 ( , , 8, 8 , , 8 @ 2 , 8 , , 8 ( ( 3, , 8 , 84
, 8 ( , 3 , 8:

>>> print(time.strftime(%d/%m/%Y, t))


27/05/2007


se of T. (Brackets) , 8 , 8 , , 8 ( , 8, 4 , 8 ( forward-slash , 8, 4, 8 , , 8 (
( 3, , 8 , 8, 4 , 8 forward-slash , 8, 8 @ , 8 , & ( - , 8@
(
se of T. (Brackets) , 8, 8 2 , 84 , 8 ( :

%a , , 83 ( , 8 2, 8 ( , ( - , 2 ( 3 , 8- Mon, Tues, Wed, Thurs, Fri,


Sat, and Sun)
%A , , 83 , 8, 8 (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)
%b , 8, , ( , 8 - , 2 (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct , Nov, Dec)
%B , 8, , 8, 8 (January, February, March, April, May, and so on)
%c , 8, 8 4 ( , , asctime &3 , 8 , 84
se of T. (Brackets) , 8 ( 3, , 8 &3 3
%d ( 3, , 8 , 8, ( ( ( , 8 , 8 2 )
%H ( , 8 (
se of T. (Brackets ,
se of T. (Brackets
se of T. (Brackets) , 8 ( , 8 , 8 2 )
%I ( , 8 (
se of T. (Brackets ,
se of T. (Brackets
se of T. (Brackets) , 8 ( , 8 , 8 2 )
%j ( 3, , 8 @, 8 ( ( ( , 8 , 8 2 )
%m ( 3, , 8 , ( , 8 , 8 2 )
%M ( 3, , 8 ( ( ( , 8 , 8 2 )
%p , , 8 AM PM
%S ( 3, , 8 , , 8
se of T. (Brackets,
%U ( 3, , 8 ( @, 8 , , 83 ( , 8 , 8 2 )
%w , , 83 ( ( ( 3, , 8 ( , , , ( , 8 2
%x , ( 4 (
se of T. (Brackets) , 8 (, 4 month/day/year- 3 , 8- // )
%X , , 8 ( ,
se of T. (Brackets) , 8 (, 4 hour:minutes:seconds- 3 , 8- 10:30:53)
%y @ ( , ( ( 3, , 8 ( 3 , 8- 3, 84 , 8 , 8 )
%Y @ ( , ( , 8 ( - )

strptime
se of T. (Brackets) strftime
se of T. (Brackets) , 8 ( W , 8 strftime ( ( a - , 8 ( 3, 8, , 8 , 8 , 8
, 8 4 ( , , 8 ( , ,
se of T. (Brackets) , 8 ( a , 8 , 8 (3 , 8
se of T. (Brackets) ( &3 , 8


( 3 :

>>> import time


>>> t = time.strptime(05 Jun 2007, %d %b %Y)
>>> print(t)
(2007, 6, 5, 0, 0, 0, 1, 156, -1)

( , 8 ( a , 8 4 ( 3 day/month/year ( 3 ( 3, , 8- 01/02/2007), &3 , 84 , 8 ( :

>>> import time


>>> t = time.strptime(01/02/2007, %d/%m/%Y)
>>> print(t)
(2007, 2, 1, 0, 0, 0, 3, 32, -1)

4 ( ( 3 month/day/year, 4 3, 8 &3 , 84 , 8 ( :

>>> import time


>>> t = time.strptime(03/05/2007, %m/%d/%Y)
>>> print(t)
(2007, 3, 5, 0, 0, 0, 0, 64, -1)

q - , 8 (
se of T. (Brackets) &3 , 84 , 8 ( , ( ( a :) , 8 (
se of T. (Brackets) , 8, 8 , 8 ( 42
, 8 , , 8 (
se of T. (Brackets) ( 3, , 8 ( ( :

>>> import time


>>> def convert_date(datestring, format1, format2):
... t = time.strptime(datestring, format1)
... return time.strftime(format2, t)
...


se of T. (Brackets) &3 , 84 , 8 ( 4 ( ( a
se of T. (Brackets) , 8, 8 , 8 ( 42 , 84 4 , 8

se of T. (Brackets) , 8, 8 4 ( ( 2 , 84 4 3, 8 :

>>> print(convert_date(03/05/2007, %m/%d/%Y, %d %B %Y))


05 March 2007


, 8 ( ( r D

'', 8, ( , 8 ( ''

( 4 & , 8 , , 8 ( @ 4 ''Things to try'' , , 8 , 8 , 8

( v48 &

. 8 8 , 4 ( , 8 , 84 3, 8:

>>> toys = [ car, Nintendo Wii, computer, bike ]


>>> foods = [ pancakes, chocolate, ice cream ]
>>> favourites = toys + foods
>>> print(favourites)
[car, Nintendo Wii, computer, bike, pancakes,
chocolate, ice cream]

. 8 8 , - , 8 ( , 8 , 8 , , 8 , 8


( , 8 , 8 ( , 8, 8 :

>>> print(3 * 25 + 10 * 32)


395

3 , ( v48 & , 8 '& , 8 , 8 &3 , 8 ( @ , 4 ( ( , 8 ( , 84 , 8 , 8 4 , 8, 8
'& , 8 , , 84 4 ( - , 8 , 84 , 8 , 8 :

>>> print((3 * 25) + (10 * 32))


395

, , 8 , 8 , 8 , 8@, , 8 , 8, ( , 8 , 8 3, 8, 8@


3, 8, 8@ 3 , ( v48 , 8 ( ( , 8 ( @ - , 8 , 8 W, 8 :)
r , 8 , 8 ( , 8 , 8 ( ( , 8 , 8 , 8 m , 8
) , 8 , 8 , 84 , 8 , 8 4 ( , , 8 , 8 4 , , 8 , 84 F
, 8
se of T. (Brackets)
se of T. (Brackets) , 8 , , 8 , 8 ,
se of T. (Brackets)
se of T. (Brackets) , 8 , , 8 , 84 F (4 3, 8 3 -
, , #2- , 8 - ) '& , 8 , 3 ( 3, ( , 8 , 84 3, 8

. ( 4 3 , 8 ( , 8 , 84 3, 8 :


>>> first_name = Maria
>>> second_name = Ahamed
>>> print(My name is %s %s % (first_name, second_name))
My name is Mary Ahamed


4H48 &

( 4-#2 2 H ( 4 , 84 , , 8 , 8 ( 2 , 8 , 8 , 8


&3 , 8 ( , 84 ( 4 3, 8 , 3, 8 4 ( ( 4-#2 Y , 84 , 8 , 8 :

( ( ( 2r ( , 8, 8 , 8 2 ( , 8


, 8 , 8
( ( , 8, 8 , 8 2 , , 8
, 8 , 8
4 ( , 8, 8 , , 8 ( , 8 ( @, 8 44 ( , 8, 8 ( , 8
, 8 , 8
( v48 4 ( , 8, 8 , , 8 ( , 8 ( @, 8 44 ( , 8, 8 , , 8

3 , 8, ( D.1 4-#2 Y , 84 ( , 8 , ( &3 3, 8 ( @ :

>>> import turtle


>>> t = turtle.Pen()
>>> t.forward(150)
>>> t.left(90)
>>> t.forward(50)
>>> t.left(90)
>>> t.forward(150)
>>> t.left(90)
>>> t.forward(50)

( ( ,-: 2 ( 4, 8 Y , 8@

( 4-#2 Y ( @ ( , 4 , 8 :) , 8 , 8 X 2& , , , 8 2 , 84 3, 8
4 ( ( ( & , 8 , , , 8 2 ( @ , 8, 8 , 8 4, 8 4 ( , 8@ 4 ( W 3, 84 , 8 , 8 4 (
, ( &3 , 8 ( , ( - Y , 84 , 8 , 8 ( ( D2 )


>>> import turtle
>>> t = turtle.Pen()
>>> t.forward(100)
>>> t.left(135)
>>> t.forward(70)
>>> t.left(90)
>>> t.forward(70)

, 8 &

print 3 , 8 loop , 8 4 4 ( 4 , 8 , 8, , 8 , ( , 8 4 (


4 , 8 , 8:

( ( ,-: 2 ( ( - Y , 8@

>>> for x in range(0, 20):


print(hello %s % x)
if x < 9:
... break
hello 0

4 ( @ (
se of T. (Brackets 3 , 8 , 8 , 8 loop , 8 2 , , 8 - ( , 8 x
#& , 834 #& , 8 @ , 4 ' , 8
se of T. (Brackets , 8, 8 , 8 , , 8

4 ( ( % - , 8 4, 8 4 , 8 , 8 4 , 8 , 4 , 8 , 8 , 8 , 8 .


( , 8 :) ( - ( , 8 X4 ( , 84 , 8 ( , , 8 , 8 , ( - , 8, , 8 (
, 84 , 8 ( :

>>> amount = 100

@, 8 :)
se of T. (Brackets , 8 , 8 , 8 4 , , 8 0.03 , 84 3, 8:


>>> amount = 100
>>> print(amount * 0.03)
3.0

( 4 ! J :) , 8 ( @ , 84 3 ( , 8 , 8 (


se of T. (Brackets , 84 3, 8
, 8 , 8 , , 8 , 84 3, 8 ( @, 8 :) ( , 84 4, 8 (
, 84 3, 8:

>>> amount = 100


>>> for year in range(1, 11):
... interest = amount * 0.03
print(interest earned for year %s is %s % (year,
interest))
amount = amount + interest
...
interest earned for year 1 is 3.0
interest earned for year 2 is 3.09
interest earned for year 3 is 3.1827
interest earned for year 4 is 3.278181
interest earned for year 5 is 3.37652643
interest earned for year 6 is 3.4778222229
interest earned for year 7 is 3.58215688959
interest earned for year 8 is 3.68962159627
interest earned for year 9 is 3.80031024416
interest earned for year 10 is 3.91431955149

, 8 for-loop X4 ( , 8 ( @, year - ( , 8 &3 , 8 ( @


se of T. (Brackets) , 8 , 8 2

se of T. (Brackets , 8 , 8@ ( v48
se of T. (Brackets , 8 , 8 , 8@ - ( , 8, 8 , 8 , , 8 . , 8 , 8@ , 8 428
, 8 (
se of T. (Brackets , 8
se of T. (Brackets - , 84 % &3 3, 8, 8@ , 84 @, 8
se of T. (Brackets , 8 , 8
, 2, 8, 8 , 8 , , 8
se of T. (Brackets (
se of T. (Brackets) , 8 , 8,
se of T. (Brackets , 8 , 8 ( @ (
se of T. (Brackets , 8 ( , 8 , 8, 8 , 8
, 8 , ( X4 ( , 8 ( 4 ( , 84 , 8 , 8 ( 4 @ 4
se of T. (Brackets , 8 , 8 ( @ , 8 (

se of T. (Brackets , 8 H ( , 8 , 8F , ( 8 3, 8 , , ( 4 @ ( @ , - , 8 :

>>> amount = 100


>>> for year in range(1, 11):
interest = amount * 0.03
print(interest earned for savings %s for year %s is %s %
(amount, year, interest))
amount = amount + interest
...
interest earned for savings 100 for year 1 is 3.0
interest earned for savings 103.0 for year 2 is 3.09
interest earned for savings 106.09 for year 3 is 3.1827
interest earned for savings 109.2727 for year 4 is 3.278181
interest earned for savings 112.550881 for year 5 is 3.37652643
interest earned for savings 115.92740743 for year 6 is 3.4778222229
interest earned for savings 119.405229653 for year 7 is 3.58215688959
interest earned for savings 122.987386542 for year 8 is 3.68962159627
interest earned for savings 126.677008139 for year 9 is 3.80031024416
interest earned for savings 130.477318383 for year 10 is 3.91431955149


&

( for-loop , 3, 8


se of T. (Brackets) , 8 , 8
se of T. (Brackets) ( , 84 3, 8:

>>> def calculate_interest(amount, rate):


... for year in range(1, 11):
... interest = amount * rate
... print(interest earned for savings %s for year %s is %s %
... (amount, year, interest))
... amount = amount + interest

( 4 ( , 8, , , 8 4 , 8 , 4 ( , 84 , 8 , 8 , , 8 ( 2 , 8, (


, 8 ( 42 3, 8, 8@ (. 3, 8 , 8& ( ) amount , 8 , 8 ( - ( , 8 , (
, 8& ( 3, 8 4 , 8 ( 42 , 8 4 (
se of T. (Brackets) ( , 8 4 , ,
, 8 , 8 , 8:

>>> calculate_interest(100, 0.03)


interest earned for savings 100 for year 1 is 3.0
interest earned for savings 103.0 for year 2 is 3.09
interest earned for savings 106.09 for year 3 is 3.1827
interest earned for savings 109.2727 for year 4 is 3.278181
interest earned for savings 112.550881 for year 5 is 3.37652643
interest earned for savings 115.92740743 for year 6 is 3.4778222229
interest earned for savings 119.405229653 for year 7 is 3.58215688959
interest earned for savings 122.987386542 for year 8 is 3.68962159627
interest earned for savings 126.677008139 for year 9 is 3.80031024416
interest earned for savings 130.477318383 for year 10 is 3.91431955149

, 8 pass
se of T. (Brackets) , 8 , 8 ( 42 , 8& ( , 8 , 8 ( 42 , 8 :

>>> def calculate_interest(amount, rate, years):


... for year in range(1, years):
... interest = amount * rate
... print(interest earned for savings %s for year %s is %s %
... (amount, year, interest))
... amount = amount + interest

, 3, 8
se of T. (Brackets ,
se of T. (Brackets , 8 , 8 3 , @, 8 , & , 8 ( 42 , 84 , 8 ( :

>>> calculate_interest(1000, 0.05, 6)


interest earned for savings 1000 for year 1 is 50.0
interest earned for savings 1050.0 for year 2 is 52.5
interest earned for savings 1102.5 for year 3 is 55.125
interest earned for savings 1157.625 for year 4 is 57.88125
interest earned for savings 1215.50625 for year 5 is 60.7753125


se of T. (Brackets) X4 ( , 8 ( @ 4 , 84 ( @ ( , 8 ( , 8 , 8 sys ( ,
, 8, 8 2 , 84 3, 8, , 84 , 8 ( , 84 , 84 , 8 ( 4 , 8 , 8 ( 4 ( , 8 :) &3 8, 8
, 8 , 84 3, 8 , 8 , 8H - , 8
se of T. (Brackets) , , 8 ( H - , 8 , 8 :


>>> import sys
>>> def calculate_interest():
... print(Enter the amount you have to save)
... amount = float(sys.stdin.readline())
print(Enter the interest rate)
rate = float(sys.stdin.readline())
... print(Enter the number of years)
... years = int(sys.stdin.readline())
for year in range(1, years):
interest = amount * rate
print(interest earned for savings %s for year %s is %s %
... (amount, year, interest))
... amount = amount + interest


se of T. (Brackets) ( , 8 4 ( , 8 , 84 , 84 , 8 , 8 :

>>> calculate_interest()
Enter the amount you have to save
500
Enter the interest rate
0.06
Enter the number of years
12
interest earned for savings 500.0 for year 1 is 30.0
interest earned for savings 530.0 for year 2 is 31.8
interest earned for savings 561.8 for year 3 is 33.708
interest earned for savings 595.508 for year 4 is 35.73048
interest earned for savings 631.23848 for year 5 is 37.8743088
interest earned for savings 669.1127888 for year 6 is 40.146767328
interest earned for savings 709.259556128 for year 7 is 42.5555733677
interest earned for savings 751.815129496 for year 8 is 45.1089077697
interest earned for savings 796.924037265 for year 9 is 47.8154422359
interest earned for savings 844.739479501 for year 10 is 50.6843687701
interest earned for savings 895.423848271 for year 11 is 53.7254308963

r &

X4 ( :) ( ( W , 8 , 8@ , ( , 3 , 8@ ( W , 8 , , 8 ( W 4, 8


( , ( :) , 8 ( , 8 , 84 3, 8:

import turtle
t = turtle.Pen()
>>> t.forward(50)
>>> t.right(45)
>>> t.forward(50)
>>> t.right(45)
>>> t.forward(50)
>>> t.right(45)
>>> t.forward(50)
>>> t.right(45)
>>> t.forward(50)
>>> t.right(45)


>>> t.forward(50)
>>> t.right(45)
>>> t.forward(50)
>>> t.right(45)
>>> t.forward(50)

4 ( , 84 , 8 , 8 , 8, 2 , 8 ( , 8, 8 , , 8 , 84 , 8 ( @ , 4, 8 , ( , 8 ( , ( (
, 84 , 8 ( @ ( , 84 , 8 ( @ :) , , 8 ( X4 ( , 3
, 8 3, 8 ( , 8 , ( ( D3 , 84 X4 ( , 8 ):

>>> for x in range(0,8):


... t.forward(50)
... t.right(45)

4 ( ( r & , 8 :) , 8 (


se of T. (Brackets) , 8 , 8 , 4 3, 8 , 8 , 8 ( - , 8 ( (
se of T. (Brackets) , , 8
X4 ( 3
se of T. (Brackets) , 8 (
se of T. (Brackets) , 8 , 8 ( 4 , 8 4 , 84 ( , 84 , 8 ( , ( , 2
3
se of T. (Brackets) &3 , 84 , 8

>>> def octagon(red, green, blue):


... t.color(red, green, blue)
... t.begin_fill()
... for x in range(0,8):
... t.forward(50)
... t.right(45)
... t.end_fill()

, , 8 ( @, 4, 8 ( , 8#2 , 8 ( @ 4 , 8 Y , 84 for-loop ( , 8 ( @


, 2, 8, 8 # (
se of T. (Brackets) ( , 8 , 8 , 8 , 8 - ( 42 ( @ ( , 8 8 ( ( ( D.4 ):

>>> octagon(0, 0, 1)

( ( ,-: 2 ( r- Y , 8@


( ( ,-: 2 ( 8 r- Y , 8@


( 2 (Index)

( , (addition) ( , , (modules)
, , (blocks of code) , (os)
( ,, (conditions ) & , (random)
( (combining) , 8, (choice)
, /
se of T. (Brackets) , 8 (date/time formats, ) & ( ,
se of T. (Brackets (randint)
( , ( ( (degrees ) & , 8, (randrange)
( , ( - (division )
se of T. (Brackets) (shuffle)
( ( (equality ) ( , , (sys)
, , 8 , 8 & , 8 , (escape characters ) ( (exit)
( , 8, 8
se of T. (Brackets (floating point ) , ( ( , (stdin)

se of T. (Brackets) - , 8 (for-loop ) , ( (stdout)

se of T. (Brackets) (functions) - , 2 (version)
( , (abs ) (time)
(bool) , ( , (asctimie)
( , ( , 8 (cmp) ( , (ctime)
( , (dir) (localtime)
- (eval) ( (/) , 8 (sleep)

se of T. (Brackets) (file) , ( ( ( , 8 (strftime)
(close) (
se of T. (Brackets) ) (time (funtion))
( , (read) ( (tkinkter)
3 (write) ( , ( , 8 (basic animation)
(float)
se of T. (Brackets,_ (bind_all)

se of T. (Brackets (int) & - , (Canvas)
(len) ( m, 8 _ ( , (create_arc)
& (max) ( m, 8 _, 8 (create_image)
( (min) ( m, 8 _ (create_line)
range) ( m, 8 _- (create_oval)
, (sum) ( m, 8 _, 8 ( (create_polygon)
3 ( , ( , , 8 , (hexadecimal colors ) ( m, 8 _ & (create_rectange)

se of T. (Brackets) - , 8
se of T. (Brackets (if-statement) , 8-
se of T. (Brackets (events)

se of T. (Brackets) - - ( , - , 8
se of T. (Brackets (if-then-else- - (move)
statement ) , , 8 , 8 (modulo operator)
8 ,2 (keywords ) ( ( a (multi-line string)

se of T. (Brackets, (and) ( ( , 8 (multiplication)
& (as) , , 8& ( (named parameters)
& 2 (assert) (none)
' (break) , 8 , 8 (operators)
(class) ,2
se of T. (Brackets) , 8 , 8 , (order of operations)
, (del) , 8 (pen)



se of T. (Brackets) (elif) ( , 8, 8 (pixels)
( , (else) , 8 (python)
, 8 (except) , 8 , 8, (python console)
, 8 (exec) ( 2 (return)

se of T. (Brackets) ( (finally) , 8 (scope)

se of T. (Brackets) (for) ( a (strings)


(from) , (subtraction)
(global) , 8 (tuples)

se of T. (Brackets) (if) 2 (turtle)


, 8, 8 2 (import) ,- (advanced)
(in) & ,2 (backword)
(is) ( (clear)
& , (lambda) (color)
(not) & (black)
(or) , ( 2 ( ) (down (start drawing
, 8 , (pass) (
se of T. (Brackets) (fill)
(raise)
se of T. (Brackets) , 8 ,2 (forward)
( 2 (return) ( , 8, (reset)
(try) (
se of T. (Brackets) (turning left)
3 (while) ( (turning right)
, 8 (placeholder-%s) (yield) , 8 (, 8 ( ) (up (stop drawing))
( (list) - ( , 8 (variable)
, 8, 8 ( , (appending) - ( , 8 , (variables)
, 8 ( (joining) - , 8 (while-loop)
( ( - (removing) , (white-space)
( , 8 ( , (replacing)

You might also like