Β ΕΠΑΛ Αρχές Προγραμματισμού Υπολογιστών

download Β ΕΠΑΛ Αρχές Προγραμματισμού Υπολογιστών

of 120

description

Β ΕΠΑΛ Αρχές Προγραμματισμού Υπολογιστών

Transcript of Β ΕΠΑΛ Αρχές Προγραμματισμού Υπολογιστών

  • [ 1 ]

    ., ., ., ., ., .

    &

    ..

  • :

    ,

    :

    :

    :

    ,

    ,

    ,

    ,

    ,

    ,

    :

    ,

    ,

    :

    , ...

    , MSc

    ,

    : /....

  • [ 3 ]

    () , ' ' .. ' ' .. , .

    .. , .

    '

    ( 2015-16)

    '

    ( 2016-17)

    1.

    * *

    (- )

    2. * *

    (- )

    3.

    * *

    (- )

    4. * *

    (- )

    5. * -

    6. * -

    7 - *

    8. * *

    9.

    - *

    10. - *

    11.

    - *

    12 - *

    13. API

    * *

    14.

    - *

    , .

    , ,

  • - '

    [ 4 ]

    . , . , , . , , , .

    , , . , . , , Python, , .

  • - '

    [ 5 ]

    1. ........................... 12

    1.1 .......... 12

    1.2 ................. 13

    1.2.1 - .......................................................................................... 16

    1.3 / ......................................... 16

    1.3.1 / ................................. 17

    1.4 .................................................................................................. 17

    1.5 ......................................................................................... 18

    1.5.1 1: ..................................... 18

    1.5.2 2: , . ........................ 18

    1.5.3 3: ....... 19

    1.5.4 4: ............................................................................. 19

    1.6 ............................................................................................. 20

    1.7 - ............................................................................. 20

    2. ................... 24

    2.1 / ......................................... 24

    2.1.1 .................................................................. 24

    2.1.2 ................................................................................ 25

    2.2 ..................................................................................................... 25

    2.2.1 ....................................................... 26

    2.2.2 ............................................................. 26

    2.2.3 ................................ 27

    2.2.4 ................ 28

    2.2.5 : ............................................................................. 28

    2.3 .................................................... 28

    2.3.1 . ......................................................................... 29

    .............................................................................................................. 30

    ....................................................................................... 31

  • - '

    [ 6 ]

    3. ............................. 34

    3.1 ..................................................................................................... 35

    3.1.1 Linux .................................. 35

    3.1.2 IDLE Python MS-Windows .................................. 36

    3.2 ............................................................. 37

    3.2.1 ................................................................................ 37

    3.2.2 ........................................................................................ 38

    3.2.3 38

    3.2.4 3.1 ........................................................................................ 40

    3.2.5 3.2 ........................................................................................ 40

    3.2.6 ...................................................... 41

    3.3 , , .................. 42

    3.3.1 3.3. ...................... 43

    3.3.2 ................................................................................. 44

    3.4 () ................................................... 44

    3.5 ................................................ 46

    3.5.1 3.4: Python .... 46

    3.6 , ......... 47

    3.6.1 ........................................................ 47

    3.6.2 ............................................ 47

    ............................................................................................ 48

    ......................................................................................................... 49

    ........................................................................................................ 49

    4. ....................................................................... 52

    4.1 - .............................. 53

    4.1.1 .......................................................................................... 53

    4.1.2 if () ....................................................................... 53

    4.1.3 (for while) ...................................................... 56

    4.1.4 while ( )59

    4.2 ............................................................................................... 61

    4.2.1 ....................................... 61

    4.2.2 ............................................................................................ 62

    4.2.3 ......................................................................... 63

    4.2.4 ................................................................................... 63

  • - '

    [ 7 ]

    4.2.5 ................................................................. 64

    4.3 .................................................... 67

    4.3.1 1 .............................................................................. 67

    4.3.2 2 .............................................................................. 67

    4.3.3 3 .............................................................................. 67

    4.3.4 4 .............................................................................. 67

    4.3.5 5 .............................................................................. 67

    4.3.6 6 .............................................................................. 68

    4.3.7 7 .............................................................................. 68

    4.3.8 8 .............................................................................. 68

    4.3.9 9 .............................................................................. 68

    4.3.10 10 ............................................................................ 68

    ........................................................................................... 68

    ...................................................................................... 68

    ........................................................................................................ 69

    5. ......................................................................... 72

    5.1 ............................................... 72

    5.2 (str) ................................................................................... 73

    5.3 .......................................................................... 76

    5.3.1 1 ...................................... 77

    5.3.2 2 ...................................... 77

    5.3.3 3 .............................................. 78

    5.3.4 4 .............................................. 78

    5.3.5 5 .............................................. 80

    5.3.6 6 .............................................. 80

    5.4 ...................................................................................................... 81

    5.5 ....................................................................................................... 82

    5.6 .................................................................................................... 82

    5.7 ........................................................................................................ 83

    5.8 ...................................................................... 85

    5.8.1 1: ............................ 85

    5.8.2 2 .............................................................................. 85

    5.8.3 3 .............................................................................. 85

    5.8.4 4 .............................................................................. 85

    5.8.5 5 .............................................................................. 85

  • - '

    [ 8 ]

    5.8.6 6 .............................................................................. 85

    5.8.7 7: .................................. 86

    5.8.8 8: ...... 86

    5.8.9 9: ....................................... 87

    5.8.10 10 ............................................................................ 87

    5.8.11 11 ............................................................................ 87

    5.8.12 12 ............................................................................ 87

    5.8.13 13 ............................................................................ 87

    .............................................................................................................. 87

    ...................................................................................... 88

    ........................................................................................................ 88

    6. .................................................................. 92

    6.1 ................................................. 92

    6.2 ................................................................................. 93

    6.3 ............................................................................ 94

    6.4 ....................................................................... 96

    6.4.1 1: .............................. 96

    6.4.2 2 .............................................................................. 96

    6.4.3 3 .............................................................................. 97

    6.4.4 4 .............................................................................. 97

    6.4.5 5 .............................................................................. 97

    6.4.6 6 .............................................................................. 97

    6.4.7 7 .............................................................................. 97

    6.4.8 8 .............................................................................. 97

    6.4.9 9 .............................................................................. 97

    ........................................................................................................ 98

    7. ..................................................................... 102

    7.1 ................................................................................................. 102

    7.1.1 ...................................................... 104

    7.2 .................................................................. 105

    7.2.1 1 ............................................................................ 105

    7.2.2 2 ............................................................................ 106

    7.3 ............................................................. 107

    7.4 .................................................................... 108

    ............................................................................................... 108

  • - '

    [ 9 ]

    ............................................................................................................ 109

    .................................................................................... 109

    - ....................................................................................... 109

    8. API ........ 112

    8.1 ................................................................................................. 112

    8.2 - ...................... 112

    8.2.1 .................................................. 114

    8.3 Tkinter GUI Python 115

    8.4 ................................................. 117

    8.4.1 1 ............................................................................ 117

    8.4.2 2 ............................................................................ 117

    8.4.3 3 ............................................................................ 118

    8.4.4 4: ............................... 118

    8.4.5 5: .......................... 118

    8.4.6 6: 118

    ................................................................................................................... 119

  • - '

    [ 10 ]

  • - '

    [ 11 ]

    1

  • - '

    [ 12 ]

    1.

    :

    ,

    - (, ).

    : , , , , , .

    : , , .

    , , , .

    1.1

    . , .

    , , , . , . : , , , .

    . . . .

    .

  • - '

    [ 13 ]

    . , () . . . . .

    . .

    .

    , . .

    1 .

    , ( ) . .

    1.2

    () . ( -Top Down), ( -Bottom Up), (Mixed) .

    (Top Down problem solving) .

    :

    1. .

    2. , .

    3. , .

    .

  • - '

    [ 14 ]

    .

    . " ". :

    (1) .

    (2) .

    (3) .

    . .

    (1) , :

    (1.1) .

    (1.2) , .

    (1.3) "".

    (2) ,

    :

    (2.1) .

    (2.2) .

    (2.3) .

    (3) , :

    (3.1) .

    (3.2) .

    (1.1) :

    (1.1.1) .

    (1.1.2) .

    (1.1.3) .

    (1.2), :

    (1.2.1) .

    (1.2.2) .

  • - '

    [ 15 ]

    (1.2.3) .

    , . . , .

    , . , :

    .

    .

    . , .

    1.1.

    . 1.1. " "

    . , .

  • - '

    [ 16 ]

    1.2.1 -

    . , :

    ( ).

    .

    . : , ;

    .

    , . . : ; .

    .

    . : ; ;

    , . ;

    . . ( ) . , . , . , , , .

    1.3 /

    . :

  • - '

    [ 17 ]

    , . , .

    (diagramming techniques), . , , (flow chart).

    (coding), .

    . .

    , . Python.

    .. ..

    1.3.1 /

    , . , , , , . , .

    4.4 .. .., .. .. : .. .. ..

    1.4

    ;

    ;

    ;

    ;

  • - '

    [ 18 ]

    1.5

    1.5.1 1:

    :

    :

    ;

    ;

    ;

    ;

    ;

    , .

    .

    : .

    1.

    100 . 10 . 9 . , ;

    2.

    . ; (>0) , ;

    1.5.2 2: , .

    5 . : . :

    , , , . .

    .

    .

    : .

  • - '

    [ 19 ]

    wiki (http://eclass.sch.gr/). : .

    :

    (http://www.0-18.gr). , http://www.0-18.gr/gia-paidia/nea/syntagi-gia-asfali-ploigisi-sto-internet ( 16/07/2015).

    , , , (http://www.saferinternet.gr, 16/07/2015).

    : (http://internet-safety.sch.gr/, 16/07/2015).

    1.5.3 3:

    quiz :

    1. . ( Cmap-tool http://cmaptools.en.softonic.com/) .

    2. , ( ) : , , ..

    3. , . . . , .

    1.5.4 4:

    . , , ( , , ..) , 20 25 C .

    , .

  • - '

    [ 20 ]

    .

    , . ; ;

    : , ;

    : .

    1.6

    1.3 ..

    1.7 -

    , ( 21 ) , 9: , , ..., (..), 2015.

    Computer Science Unplugged: http://www.csunplugged.org ( 12/07/2015).

    : http://games.thinkingmyself.com/ ( 12/07/2015).

    . O Wolfram Demonstrations Project, Stephen Wolfram. / , , , . Wolfram CDF Player ( ). (on-line) -browser.

    http://demonstrations.wolfram.com/topics.html?Algorithms#123 ( 15/07/2015)

    : http://www.teaching-materials.org/algorithms/ ( 05/01/2015).

  • - '

    [ 21 ]

    - . ( 05/07/2015) http://photodentro.edu.gr/lor/subject-search?locale=el

    on-line https://www.gliffy.com ( 15/07/2015).

    ( Cmap-tool http://cmaptools.en.softonic.com/, 15/07/2015).

  • - '

    [ 22 ]

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

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

    ..

    ..

    ..

    ..

  • - '

    [ 23 ]

    2

  • - '

    [ 24 ]

    2.

    :

    (, ).

    , , , , .

    2.1 /

    , .

    () (Waterfall model) (Spiral model).

    2.1.1

    :

    .

  • - '

    [ 25 ]

    2.1.2

    , ... .

    , , " " (program development life cycle-PDLC).

    , :

    .

    .

    .

    .

    .

    :

    ) , .., , -

    ) , . ., , 17, ' , 18, .

    2.2

    1960 .

  • - '

    [ 26 ]

    , (programming paradigms).

    :

    (imperative programming).

    (declarative programing).

    2.2.1

    , , . , Cobol, Fortran, Pascal, C ..

    2.2.1.1

    , goto, ( - unstructured programming). (structured programming), (blocks) , if-then-else.

    (procedural programming) , , , (procedures). - Pascal, 1970.

    (object-oriented programming) , , , .

    2.2.2

    (declarative programming paradigm) , . , .

    (functional programming) , Lisp, Logo ..

    (logic programming) . .

    , . HTML (HyperText Markup Language), - SQL

  • - '

    [ 27 ]

    (Structured Query Language) , (RDBMS-Relational Database Management System).

    2.2.3

    , , .

    (parallel programming), .

    (event-driven programming). , . (events), . Microsoft Visual-Basic.

    (visual programming). , , . (icon-based languages), (diagram languages) (form based languages).

    Authorware Adobe, Kodu Microsoft Alice MIT Scratch.

    (script programming) , . , .

    (modular programming), . , ... , . (module) .

    , . , , , . (top down design).

  • - '

    [ 28 ]

    : , ., , 7, 3 (7.3) .

    2.2.4

    Pascal. .

    Visual Basic (http://www.microsoft.com). , .

    C++. C. , -.

    Java. .

    Python (http://python.org/about/). , , .

    Prolog (Programming in Logic). .

    2.2.5 :

    1. , .

    2. , .

    3. , . (multiparadigm environments).

    . , : Object Pascal - Apple Computer, Delphi Borland 2006, C, C#, C++, Java, Eiffel, Kodu Microsoft, AppInventor, Greenfoot.

    2.3

    (Object-oriented programming - OOP). (Class), (Objects), (Properties) (Methods).

    ' " " ., . 11 11.1 11.2.

  • - '

    [ 29 ]

    1

    :

    : , , ,

    : ,

    , 1" : : ", : 10000, : 4, : 0 km/h, 2" : : , : 4000, : 2, : 0 km/h. , 1 2, . . , .

    2

    :

    : ,

    : ,

    1 . , . . , .

    2.3.1 .

    (.. www.sploder.com) :

    3 , 2 . 2 . . , (terrains) .

    :

    1: , . ( ).

  • - '

    [ 30 ]

    2: . .

    . ;

    .

    ; v ;

    3:

    ; ; ;

    4: :

    ; ;

    ;

    ;

    , ;

    ; ;

    ;

    , , ;

    5: .

    ;

    ;

    ;

    ;

    ;

  • - '

    [ 31 ]

    , ., , 7, 3 (7.3)

    , .., , -

    , . ., , 17. ' 18. .

  • - '

    [ 32 ]

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    .

  • - '

    [ 33 ]

    3

  • - '

    [ 34 ]

    3.

    :

    Python

    Python

    Python, , , ,

    Python

    .

    , , , , , , , , , .

    Python. , , , , , . , , . C++, Java, Perl, Ruby, Processing.

    , . - "", .

    Python, , , . Python , , .

  • - '

    [ 35 ]

    , , .

    Python, , - , , . , . , .

    . . , . , . , .

    3.1

    Python, . , :

    Python

    .

    Python () . 2.7.10 Python.

    To IDLE (Integrated Development Environment) Python , , , S Windows, Linux, MAC OS X.

    3.1.1 Linux

    , Linux Python o. , (Software Centre) ( UBUNTU).

  • - '

    [ 36 ]

    3.1.2 IDLE Python MS-Windows

    IDLE Python https://www.python.org/. (2.7.10), Windows , . . : Python IDLE ( 3.1).

    3.1: IDLE

    IDLE , . , , >>>.

    T Python Shell, ( >>>) .

    :

    : , !. print, () .

    >>> print ", !"

    , !

    Python, , , FileSave As (, ) . , . Python. / File (Open), . Python .py.

    (editor) IDLE . :

  • - '

    [ 37 ]

    File (New File), ,

    (Save, .py),

    RunRun Module ( F5), Python Shell.

    3.2

    3.2.1

    "_" . , ( barcode reader). . Python .

    Python , (booleans) ( strings)

    Python : (integers), (floating point) (complex numbers) ( ' ).

    3, ( ).

    3.14 28.2E-5, E 10, ( floats ). , 28.2.3E-5 28.2 * 10-5.

    , (-2+3j).

    (boolean) , True () False () .

    . " ". , Unicode. , ' ! " !", . .

    (). 34 + 56 3.14*8.

  • - '

    [ 38 ]

    3.2.2

    . .

    , . . . . . , , supermarket. . "" , , ..

    . . . bit (0,1) . bits . , , , .

    Python , . , (, , , ..).

    3.2.3

    , . Python . , . , onoma1, onoma_2, timi, mesi_timi, embado .. Python , .

    = . . To = , . =234 234 ( ) .

  • - '

    [ 39 ]

    print ( print a 234).

    :

    >>>x = 10 # 10 x

    >>>print x # x

    10

    >>>x=x+15

    # x 15 x

    >>>print x

    25

    >>>x=x *0.1

    # x 0.1 x.

    >>>print x

    2.5

    >>>print x*100

    250.0

    >>>onoma = # onoma

    >>>print onoma

    >>> metavliti1=metavliti2=metavliti3=15 # 15

    >>>x, y=10, 18

    >>>print x,y

    10 20

    >>>x, y, z = 10, 20, # 10 x, 20 y z.

    >>>print x,y,z

    10 20

    >>>print + z

  • - '

    [ 40 ]

    3.2.4 3.1

    x 12 y 20. x (2) ( ) 12 (). y (3) ( ) 20 (). , x ( B(2)) y y ( (3)) x.

    . Python, x, y .

    , ( ).

    3.2.5 3.2

    Python:

    ( #).

    arithmos, 1.234 ( ).

    arithmos_tetragwno, arithmos.

    arithmos, arithmos_tetragwno.

    logikh, True.

    paixnidia, 10.

    paixnidia, (paixnidia == 8, paixnidia > 8, paixnidia == 8 or paixnidia == 10, paixnidia ==9 and paixnidia == 10).

    .

    >>> #

    >>> arithmos = 1.234

    >>> arithmos_tetragwno = arithmos ** 2

    >>> print arithmos, arithmos_tetragwno

    : 1.234 1.522756

    >>> logikh = True

    >>> print logikh

    : True

    >>> paixnidia = 10

  • - '

    [ 41 ]

    >>> paixnidia == 8

    False

    >>> paixnidia == 8 or paixnidia == 10

    True

    >>> not paixnidia == 8

    True

    >>> paixnidia >= 8

    True

    >>> paixnidia != 8

    True

    >>> paixnidia >>

    not, or and . , .

    3.2.6

    , .

    . Python.

    x = 45

    x = 45.5

    print x

    print x + x

  • - '

    [ 42 ]

    x= ""

    y = ""

    print "", y, "", x

    print "", x + y

    x = 12

    print x + 3

    x = 26

    x = y = z = 23

    print x, y, z

    x = y = ""

    print x, y

    x , y, z = "","", 2

    print x, y, z

    print x, y * z

    x , y = 8, 12

    print x, y

    a = 010

    print a

    a = 0xA

    print a

    3.3 , ,

    , Python.

    (Arithmetic operations): +, -, *, /, **, %

    : ==, !=, , =

    : not, or, and,

  • - '

    [ 43 ]

    P Q P and Q P or Q Not P

    TRUE TRUE TRUE TRUE FALSE

    TRUE FALSE FALSE TRUE FALSE

    FALSE TRUE FALSE TRUE TRUE

    FALSE FALSE FALSE FALSE TRUE

    3.3.1 3.3.

    .

    Python.

    .

    Python.

    2 + 3

    3560 130

    5 * 3 + 2

    5 * (3 + 2)

    5 * (3 + 2) / 10

    3 * 3.75 / 1.5

    5 ** 2

    3 ** 4

    .......

    : , Python; .

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

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

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

  • - '

    [ 44 ]

    Python; ; .

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

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

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

    3.3.2

    Python.

    print, , : print _, print , print , print onoma_ ()

    =, : _= .

    , , .

    _= input()

    x = input(" : " )

    raw_input:

    name = raw_input( : )

    raw_input input . input .

    , , #. .

    3.4 ()

    Python .

    Python, :

    float() .

    int()

    abs()

    pow(a,b)

    H divmod(x,y) x/y

  • - '

    [ 45 ]

    >>> float (10)

    10.0

    >>> int(5.678)

    5

    >>> abs(-45)

    45

    >>> divmod (10,3)

    (3, 1)

    >>> pow (2,3)

    8

    # input() int()

    a=int(input( :))

    >>> a=int(input(' : '))

    : 2345.10 # 2345.10

    >>> print a

    2345 #

    Python.

    Python (math module) . (module) . , : >>> import math.

    , . (dot notation). sqrt().

    >>>import math

    >>> riza=math.sqrt(2)

    >>> print riza

    1.41421356237

  • - '

    [ 46 ]

    >>> math.sqrt(3)

    1.7320508075688772

    >>> x=math.pi

    >>> print x

    3.14159265359

    () python, . project . . .

    3.5

    Python. , ( #) . , Python . ( , ).

    3.5.1 3.4: Python

    10 15. = (*)/2. Python.

    Python

    _

    10

    15

    (*)/2

    #

    BASH = 10

    YPSOS = 15

    EMBADO = (BASH * YPSOS)/ 2

    print 'TO EMBA : ', EMBADO

  • - '

    [ 47 ]

    :,

    _

    :

    TO EMBA : 75

    Python, . , . .

    3.6 ,

    3.6.1

    , (CPU) . :

    (compilers)

    (interpreters).

    , . , . , (source code), , (executable). , .

    Python . : (interactive mode) (script mode). , Python :

    >>> 15 + 1

    16

    , >>>, (prompt) . 15 + 1, , 16. , , .

    3.6.2

    :

  • - '

    [ 48 ]

    , Python . , ( ). , . : print print SyntaxError: EOL while scanning string literal.

    , . . : , ..

    , . , , , . : , .

    , :

    . Python . Print print.

    . ( , ).

    _ - .

    .

    (),{},[].

    , Python .

    , .

    Python ( 2 3), .

    Python;

    ;

    Python;

    (boolean) ;

    Python ;

  • - '

    [ 49 ]

    ;

    Python;

    ;

    ;

    . ., o , . (2013) Python, , .

    , ., (2010), Taspython. Python B, . Python , TasPython.

    Downey, A. (2012) Think Python, How to think like a computer scientist, O Reilly. http://www.greenteapress.com/thinkPython/. .

    Swaroop, C., H. (2013) A byte of Python, http://www.swaroopch.com/notes/Python/ Creative Commons Attributions ShareAlike 4.0 International License. Ubuntu. http://ubuntu-gr.org/ .

    , ( 21 ) , 9: , , ..., (..), 2015.

    Python, https://www.Python.org/ ( 10/07/2015)

    Python, http://www.Pythonschool.net/ ( 09/07/2015)

    , http://el.wikipedia.org/wiki/Python ( 4/07/2015)

  • - '

    [ 50 ]

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

  • - '

    [ 51 ]

    4

  • - '

    [ 52 ]

    4.

    :

    , , , .

    Python.

    Python.

    .

    , , , , .

    Python. , . , , . , :

    : . (, , barcode, ) ( , usb flash memory, DVD) . input(), .

    : . (, , ), , , . , , , .

    : , . / , . , Python print.

  • - '

    [ 53 ]

    4.1 -

    4.1.1

    , .

    4.1.1.1 :

    (Ohm) V =220 Volt R= 25 ohm.

    #

    V = 220

    R = 25

    I = V / R

    print (" H :", I, " A")

    4.1.2 if ()

    , , if (AN) . if , if if.

    If :

    # if

    #

    #

    a=int(input(' '))

    if a

  • - '

    [ 54 ]

    _ :

    if :

    #

    else:

    #

    : , , ( ) . .

    Python elif. :

    if :

    elif :

    else:

    4.1.2.1 : _

    . 18 , .

    Python

    :

    age

    A age >= 18 T

    _

    age = input (" : ")

    if age >= 18:

    print(" ")

    else:

    print(" ")

  • - '

    [ 55 ]

    4.1.2.2 : -

    ) .

    ;

    6, 10, 12, 15, 18, 20;

    25; .

    ) , .

    #

    test = input(' :')

    if test= 18:

    print ' '

    # 18

  • - '

    [ 56 ]

    4.1.2.3 : - ,

    32 , , 16 , .

    temperature = int(input(" ; "))

    if temperature >= 32:

    print(" ")

    elif temperature 0:

    print(" ")

    else:

    print(" 0")

    4.1.3 (for while)

    , . :

    , .

    , .

  • - '

    [ 57 ]

    , . . , for while , Python.

    for . range().

    for onoma_metavlitis in range (, , ):

    1

    2

    ..

    : For

    (5) !

    for metritis in range (5):

    print " !"

    4.1.3.1 range

    H range() Python, , , .

    range (, , ), , , . , , . .

    4.1.3.2

    range Python . :

    range(10) : [0,1,2,3,4,5,6,7,8,9].

    range(1, 8) : [1,2,3,4,5,7]

    range(0, 35, 5) : [0,5,10,15,20,25,30]

    range(8, -1, -1) [8, 7, 6, 5, 4, 3, 2, 1, 0]

  • - '

    [ 58 ]

    4.1.3.3 : for

    for

    ) Python .

    Python

    Sum 0

    i 1 5

    x

    Sum Sum+x

    _

    Sum

    _

    sum = 0

    for i in range(5):

    x = int(input(" : " ))

    sum = x + sum

    print('To ', sum)

    ) Python 1+2+3+...+100

    Python

    Sum 0

    i 1 100

    Sum Sum+i

    _

    Sum

    #

    sum = 0

    for i in range(1, 101):

    sum = sum + i

    print(sum)

    ) Python :

    1+1*2+1*2*3++1*2*3**

  • - '

    [ 59 ]

    4.1.4 while ( )

    O while , , .

    While _ :

    1

    2

    .

    1: , . .

    2: while , .

    4.1.4.1 : while

    while

    ) , while, 2.

    Python

    Sum 0

    I 1

    #

    sum = 0 #

    i=1 #

  • - '

    [ 60 ]

    I

  • - '

    [ 61 ]

    print(" . ")

    metriti = metriti + 1

    print (" M ", metriti, " ")

    4.1.4.3 :

    .

    thenum = random.randint(1,100)

    print " 1 100."

    print " ;"

    guess = 0

    while guess != thenum:

    guess=input(" : ")

    if guess>thenum:

    print " "

    if guess

  • - '

    [ 62 ]

    (:). :

    def tragouda ():

    print('! ! ! ')

    #

    tragouda() #

    tragouda() #

    tragouda . tragouda , ' . , . , . epanalave_tragouda(), tragouda . . epanalave_tragouda(), 4 .

    def epanalave_tragouda():

    tragouda()

    tragouda()

    #

    epanalave_tragouda()

    def epanalave_4fores():

    epanalave_tragouda()

    epanalave_tragouda()

    #

    epanalave_4fores()

    4.2.2

    Python. , :

  • - '

    [ 63 ]

    >>> def print2():

    print ********

    print ********

    >>> print2()

    ********

    ********

    >>> def print2():

    print ********

    print ********

    ********

    >>> print2()

    ********

    , print . . , .. _, end_def .. , , .

    4.2.3

    Python :

    def ( [ { } ] ):

    [ return ]

    [ ] . . .

    4.2.4

    , , add times3 :

    def add(arg1, arg2):

    result = arg1+arg2

    return result

    def times3(arg):

    ginomeno = 3*arg

    return ginomeno

    >>> add(10, 18)

    28

    >>> add(10, 18.5)

    28.5

    >>> times3(10)

    30

  • - '

    [ 64 ]

    , .

    >>> times3(2.5)

    7.5

    >>> times3(python)

    python python python

    >>> times3( times3( 9 ) )

    9 9 9 9 9 9 9 9 9

    >>> times3(add(add(ab,ba), ))

    abba abba abba

    , , .

    4.2.5

    , , . , .

    . . : , .

    , math.pi . , math.pow, , .

    def ginomeno (a,b):

    x = a * b

    return x

    print (ginomeno(5,10))

    : Python (call-by-value), ,

  • - '

    [ 65 ]

    - , :

    def increment(a, b):

    a = a + 1

    b = b + 1

    return a+b

    #

    z = 1

    w = 2

    q = increment( z, w )

    print z, w, q

    1 2 5

    z, w ( ) increment, q. .

    4.2.5.1 - 1

    Python .

    printPython3, Python (3) . printPython9, Python (9) .

    def printPython3():

    print Python

    print Python

    print Python

    def printPython9():

    print Python

    print Python

    print Python

    print Python

    print Python

    print Python

    print Python

    print Python

    print Python

    printPython9 ;

  • - '

    [ 66 ]

    21 Python, printPython3() printPython9().

    4.2.5.2 - 2 ( )

    Python

    def printPython3():

    for i in range(3):

    print Python

    def printPython12():

    for i in range(12):

    print Python

    def printPython100():

    for i in range(100):

    print Python

    printPython Python :

    def printPython( ____ ):

    for i in range( N ):

    print Python

    >>> printPython(3)

    >>> printPython(9)

    >>> printPython(21)

    >>> printPython(100)

    ;

    ;

    4.2.5.3 - 3 ( )

    , .

    4.2.5.4 - 4

    Python . :

    #

    def add(arg1, arg2):

    result = arg1+arg2

    return result

    def times3(arg):

    result = 3*arg

    return result

    #

    add(10, 18)

    add(10, 18.5)

    add(Python , 3.4)

  • - '

    [ 67 ]

    times3(100)

    times3(2.5)

    times3(Python)

    , .

    4.3

    4.3.1 1

    Python . .

    4.3.2 2

    Python r (2*r), (2**r) (*r2). , ( : ).

    4.3.3 3

    Python +=0, A .

    4.3.4 4

    R1 R2. R . : . R=R1+R2. 1/R=(1/R1)+(1/R2).

    Python :

    R1 R2

    o ( 1 2 ) R1 R2

    ( ) R

    R1, R2, R.

    4.3.5 5

    Python 1+2+3+4+ 2000.

  • - '

    [ 68 ]

    4.3.6 6

    Python (o .. 131, 797).

    4.3.7 7

    Python Fibonacci.

    4.3.8 8

    Python pow.

    4.3.9 9

    Python 50 500 3.

    4.3.10 10

    , ! .

    != 1, = 0

    !=1*2*3*.(-1)*, >0

    , >=0 .

    ;

    if..else;

    for, .

    H range(1, 40, 5) ;

    for while;

    while;

    Python;

    ;

    ., ., o ., . (2013), Python, , .

  • - '

    [ 69 ]

    , ., (2010), Taspython. Python B, . Python , TasPython.

    Downey, A. (2012) Think Python, How to think like a computer scientist, O Reilly. http://www.greenteapress.com/thinkPython/. .

    Swaroop, C., H. (2013) A byte of Python, http://www.swaroopch.com/notes/Python/ Creative Commons Attributions ShareAlike 4.0 International License. Ubuntu. http://ubuntu-gr.org/ .

    , ( 21 ) , 9: , , ..., (..), 2015.

    Python, https://www.Python.org/ ( 10/07/2015)

    Python, http://www.Pythonschool.net/ ( 09/07/2015)

    Tutorial Python Python ( 03/07/2015),

    https://docs.Python.org/2/tutorial/controlflow.html

  • [ 70 ]

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

  • - '

    [ 71 ]

    5

  • - '

    [ 72 ]

    5.

    :

    ,

    .

    , . Python , , . , Python.

    Python, . (tuple) . , .

    5.1

    , . , . , . , . . Python (tuples), .

  • - '

    [ 73 ]

    . , . , . python. , , , .. python , . (str) , .

    , . ., , 17, ' , 14 16 .

    5.2 (str)

    , , Unicode. .

    5.2.1.1 1 :

    . .

    :

    Python

    a

    b

    z a b.

    d a * 2.

    a, b, z, d

    a = " "

    b = " "

    z = a + b

    d = a * 2

    print a

    print b

  • - '

    [ 74 ]

    len() b

    o b b[1]

    b[11 : 15]

    print z

    print d

    len(b)

    15

    b[1]

    b[11 : 15]

    python str . , . python 0. len .

    >>> word = python

    >>> letter = word[1]

    >>> print( letter )

    y

    >>> print( word[0] )

    P

    >>> python[0]

    p

    >>> len( word )

    6

    >>> len( 123 )

    3

    :. word[:] , .

    >>> s = Monty Python

    >>> s[0:5]

    Monty

    >>> s[6:len(s)]

    Python

    >>> s[len(s)-1]

    n

    >>> s[-1]

    n

    >>> s[0:len(s)]

    Monty Python

    , . . s : .

  • - '

    [ 75 ]

    >>> word = s #

    >>> word = s[:] # s word

    in . . .

    str . (dot notation). str . str, interpreter: dir(str). dir .

    >>> word = monty

    >>> python.upper()

    PYTHON

    >>> word.find(y)

    4

    >>> a in python

    False

    >>> y in python

    True

    >>> word ==

    monty

    True

    >>>antonis > antonia

    True

    >>> 1000 < 2

    True

    (Help) . : word.capitalize(), word.upper(), word.lower().

    str , (immutable). . word[0] = p , . : + .

    Python , :

    >>> def times( a, b ):

    return a * b

    >>> times( 2, 3 )

    6

    >>> times( python#, 3 )

    python#python#python#

  • - '

    [ 76 ]

    ;

    Python + Python + Python = 3 * Python .

    , (lazy evaluation). . times( Python, Java ); ;

    5.3

    Python . . :

    >>> fruits = [apple, orange]

    >>> list2 = [50,60,70,80]

    , . , .

    daysofweek=

    ["","","","","","",""]

    . , in len. :

    >>> list1 = [10,20,30,40]

    >>> fruits = [apple, orange]

    >>> len(list1)

    4

    >>> print( fruits[0] )

    Apple

    >>> apple in fruits

    True

    >>> list2 = [50,60,70,80]

    >>> list1+ list2

    [10, 20, 30, 40, 50, 60, 70, 80]

    >>> list1 + fruits

    [10, 20, 30, 40, apple, orange]

    >>> [1,0]*4

    [1,0, 1,0, 1,0, 1,0]

    - None, , array = [None]*N.

    : . (immutable), .

    >>> a =

    [5,8,13,21,34]

    >>> len( 123 )

    3

    >>> s[len(s)-1]

    n

  • - '

    [ 77 ]

    >>> a[2]

    13

    >>> a[2] = 0

    >>> print( a )

    [5, 8, 0, 21, 34]

    >>> a[1:4]

    [8, 0, 21]

    >>> s = Monty Python

    >>> s[0:5]

    Monty

    >>> s[6:len(s)]

    Python

    >>> s[-1]

    n

    >>> s[0:len(s)]

    Monty Python

    5.3.1 1

    . . Python. ;

    daysofweek=

    ["","","","","","",""]

    >>> print " ", daysofweek[6]

    : ;

    :

    : ..

    5.3.2 2

    . . . Python.

    x = [21, 23, 25, 27]

    y = [5, 6, 7, 8]

    z = x + y

    print (z)

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

    print (z [1])

    .........

  • - '

    [ 78 ]

    z[0] = 45

    print (z)

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

    a = [x,y]

    print (a)

    print (a [1][2])

    ......

    5.3.3 3

    . , print. ;

    >>> for a in [15,27,31]:

    .... print a,

    :

    daysofweek =

    ["","","","","","",""]

    for item in daysofweek:

    print (item),

    :

    5.3.4 4

    . ; . ;

    listX = [1, 2, 3]

    listY = listX

    print 'listX =', listX, 'list =', listY

    listX[1] = 5000

    print 'listX =', listX, 'list =', listY

  • - '

    [ 79 ]

    listY[2] = 100

    print 'listX =', listX, 'list =', listY

    ..

    .

    . :

    append:

    extend:

    sort:

    pop/del/remove: .

    >>> a=[5,8,13,21,34]

    >>> a.append(55)

    >>> print( a )

    [5, 8, 13, 21, 34, 55]

    >>> a.pop()

    55

    >>> print( a )

    [5, 8, 13, 21, 34]

    >>> a.pop(2)

    13

    >>> a.extend( [ 1, 2, 3 ]

    )

    >>> print( a )

    [5, 8, 21, 34, 1, 2, 3]

    : Python,

    >>> a = [5,8,13,21,34]

    >>> b = a[ : ] #

    >>> d = a #

    >>> a.pop() # a d

    34

    >>> d.pop()

    21

  • - '

    [ 80 ]

    >>> a[0]=a[1]=6

    >>> print( a )

    [6, 6, 13]

    >>> print( d )

    [6, 6, 13]

    >>> print( b ) # b

    [5, 8, 13, 21, 34]

    + . [ ]:

    >>> a = [5,8,13,21,34]

    >>> b = a + [ ]

    >>> a[0]=a[1]=a[2]=a[3]=0

    >>> print( a )

    [0, 0, 0, 0, 34]

    >>> print( d )

    [5, 8, 13, 21, 34]

    5.3.5 5

    . , .

    : : append(X) , insert (i, x) x i , pop(i) i .

    5.3.6 6

    . .

    sqlist=[ ]

    for x in range(1,11):

    sqlist.append(x*x)

    print sqlist

  • - '

    [ 81 ]

    5.4

    Python . . 0. , Python None.

    .

    >>> def newArray(size):

    array = [ ]

    for i in range(0,size):

    array.append( 0 )

    return array

    >>> a = newArray(5)

    >>> a[1] = a[3] = 1

    >>> print( a )

    [0, 1, 0, 1, 0]

    Python, 0 1.

    "" - : a = 5*[0]. append +.

    , , Python:

    Python

    for item in array :

    print item

    N = len(array)

    for i in range(0, N):

    print array[i]

    i 0 N1

    array[i]

    _

    Python . , :

    >>> matrix = [ [1, 2, 3], [4,5,6], [7,8,9] ]

    >>> print( matrix[0] )

    [1, 2, 3]

    >>> print( matrix[0][2] )

    3

  • - '

    [ 82 ]

    , .

    ; append.

    Python

    for i in range(0,3):

    a.append( [ ] )

    for j in range(0,3):

    a[i].append(0)

    i 0 2

    j 0 2

    a[i][j] 0

    _

    _

    . a[i, j] Python a[ i ][ j ]. .. a[2] . , Python.

    append pop, () () . .

    5.5

    Python . . (, , ).

    >>> myset = set( [ 1 ,2, 3, 1, 2, 3, 1, 2, 3, 8])

    >>> myset

    set( [8, 1, 2, 3] )

    >>> myset.intersection( set( [1, 2, 90] ) )

    set( [1, 2] )

    5.6

    (immutable), (tuple). . , , , , , .. . :

  • - '

    [ 83 ]

    >>> rec = a, b, 120, r

    >>> print( rec )

    (a, b, 120, r)

    >>> rec[2]

    120

    >>> len( rec )

    4

    >>> rec[1:3]

    (b, 120)

    >>> rec = (apple ,) + rec[2:3]

    >>> print( rec )

    ( apple, 120 )

    / , . .

    , :

    >>> a , b = b, a

    5.7

    (built-in) Python. . (array) . Version[python] = 3.4. , - . .

    - . :

    >>> dictionary = { :2, :4, :8, :16 }

    >>> list(dictionary.keys() )

    [A, , , ]

    >>> dictionary []

    8

    >>> len(dictionary )

    4

    >>> del dictionary []

    >>> del dictionary []

    >>> print( dictionary )

  • - '

    [ 84 ]

    {:4, :16}

    >>> dictionary [] = 32

    >>> print( dictionary )

    {:4, :32, :16}

    >>> in dictionary

    True

    (del), in.

    , []= { : }. , .

    . .. 1 :

    Python , .

    graph = { A: [B, C, D],

    B: [D]

    C: [D]

    D: [B, C] }

    1

    .

  • - '

    [ 85 ]

    5.8

    5.8.1 1:

    1000, :

    )

    )

    )

    )

    ) ,

    . .

    5.8.2 2

    , push (), pop () .

    5.8.3 3

    , enqueue (), dequeue () .

    5.8.4 4

    , 0. .

    5.8.5 5

    100 , . .

    5.8.6 6

    ISBN. ISSN. 000 ISBN ISSN.

    : (str) , .. ISBN, ISBN .

  • - '

    [ 86 ]

    5.8.7 7:

    . . 0 . , .. 4, 6, 10, 145 100, 98, 10. . ., .. 4, 6, 10, 10, 98, 100, 145.

    5.8.8 8:

    , , .

    >>>cipher = { A:X, B:Y,C: Z,D: A, , X:U}

    text , :

    >>> def encryptCeasar( text, alphabet ):

    cipherText =

    for letter in text:

    if letter in alphabet:

    cipherText = cipherText + cipher[letter]

    else:

    cipherText = cipherText + letter

    return cipherText

    - cipher. .

    : , encryptCeasar .

  • - '

    [ 87 ]

    5.8.9 9:

    Python , abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz, .

    5.8.10 10

    ( .. , RADAR) .

    5.8.11 11

    . .

    sqlist=[ ]

    for x in range(1,11):

    sqlist.append(x*x)

    print sqlist

    5.8.12 12

    Python .

    5.8.13 13

    Python end

    . (: ).

    s.

    ;

    Python;

    Python ;

    - ;

    ;

    ;

  • - '

    [ 88 ]

    , ., (2010), Taspython. Python B, . Python , TasPython.

    Downey, A. (2012) Think Python, How to think like a computer scientist, O Reilly. http://www.greenteapress.com/thinkPython/. .

    Swaroop, C., H. (2013) A byte of Python, http://www.swaroopch.com/notes/Python/ Creative Commons Attributions ShareAlike 4.0 International License. Ubuntu. http://ubuntu-gr.org/ .

    , ( 21 ) , 9: , , ..., (..), 2015.

    Python, https://www.Python.org/ ( 10/07/2015)

    Python, http://www.Pythonschool.net/ ( 09/07/2015)

  • - '

    [ 89 ]

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ..

    ....

    ..

  • - '

    [ 90 ]

    ..

    ..

    ..

    ..

    ....

    ..

    ..

    ..

    ..

    ..

    ....

    ..

    ..

    ..

    ..

    ..

    ....

    ..

    ..

    ..

    ..

    ..

    ....

    ..

    ..

    ..

    ..

    ..

    .....

  • [ 91 ]

    6

  • - '

    [ 92 ]

    6.

    :

    .

    - , . , , .

    6.1

    , . . .

    , :

    ( , ) = ( , mod )

    , , 100 36:

    ( 100, 36 ) = ( 36, 28 ) = ( 28, 8 ) = ( 8, 4 ) = ( 4, 0 ) = 4

    = 0. Python :

    Python

    def times( a, b ) :

    while b > 0 :

    a, b = b, a % b

    return a

    // , //

    > 0

    mod

  • - '

    [ 93 ]

    _

    // //

    . python , . , , .

    6.2

    . , , .. . , , . :

    ( 1.0)

    Python

    def linearSearch( array,

    key ) :

    found = False

    for item in array :

    if item == key :

    found = True

    return found

    _

    // , //

    =

    _

    _

    // //

    _

    1.0 . , . /position.

  • - '

    [ 94 ]

    : 1 . , 2.0 .

    ( 2.0)

    Python

    def linearSearch( array, key ) :

    pos = 1

    i 1

    while pos < 0 and i

  • - '

    [ 95 ]

    . , , . . , , . ( ) .

    (selection sort). :

    1: .

    2: .

    1: .

    Python :

    (Selection Sort) 1.0

    Python

    def selectionSort( array ) :

    N = len( array )

    for i in range(0, N) :

    pos = posMin( i, N, array)

    array[ i ], array[pos] = array[pos],

    array[ i ]

    _

    // , //

    i 0 N1

    _(i, N)

    A[ i ], A[]

    _

    // //

    _

    .

    Python

    def posMin( start, end, array ) : _

    // , , //

  • - '

    [ 96 ]

    pos = start

    for i in range(start, end) :

    if array[ i ] < array[ pos ] :

    pos = i

    return pos

    i 1

    A[ i ] < A[]

    i

    _

    _

    // //

    _

    , 7 , :

    i=0 i=1 i=2 i=3 i=4 i=5 i=6

    0 6

    0

    2

    0

    2

    0

    20 2

    0

    20 20

    1 3

    8

    3

    8

    3

    2

    32 3

    2

    32 32

    2 9

    8

    9

    8

    9

    8

    38 3

    8

    38 38

    3 5

    4

    5

    4

    5

    4

    54 5

    4

    54 54

    4 3

    2

    3

    2

    3

    8

    98 9

    8

    60 60

    5 9

    0

    9

    0

    9

    0

    90 9

    0

    90 90

    6 2

    0

    6

    0

    6

    0

    60 6

    0

    98 98

    6.4

    6.4.1 1:

    , python.

    6.4.2 2

    , . ;

  • - '

    [ 97 ]

    6.4.3 3

    :

    ( 3600, _____ ) = ( 1100, _____ ) = (_____,_____ ) = (_____, 100 ) =

    (_____,_____ ) = 100

    .

    6.4.4 4

    .

    6.4.5 5

    .

    6.4.6 6

    .

    6.4.7 7

    . , , , . , .

    6.4.8 8

    .

    6.4.9 9

    , .

    .

    ;

    ;

  • - '

    [ 98 ]

    ;

    , ( 21 ) , 9: , , ..., (..), 2015.

    Python, https://www.Python.org/ ( 10/07/2015)

  • - '

    [ 99 ]

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    ..

    .

    .

    .

    .

  • - '

    [ 100 ]

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

  • [ 101 ]

    7

  • - '

    [ 102 ]

    7.

    (8 ) :

    (.. ) (open, close, read, write) Python.

    -

    , , , , , , ,

    7.1

    ( ) , . .

    . , .

    , DVD_ROM, (flash memory). Python.

    , , . open()

    : , DVD (flash memory).

    : .

    : .

    : .

    : .

    : .

  • - '

    [ 103 ]

    . .

    X = open (_, )

    # open() Python . :

    (words.txt), .

    () . (w , r ).

    # . .

    >>> keimeno = open('words.txt')

    # keimeno words.txt. keimeno .

    , . open() .

    r

    w

    ( , )

    a

    ( )

    b

    +

    r+ .

    Python , . read(), readline() write() .

  • - '

    [ 104 ]

    open() .

    , , . , . , ( "r").

    , close(), .

    7.1.1

    , 'w' :

    >>> keimeno = open('output.txt', 'w')

    # output.txt w keimeno, print keimeno :

    >>> print keimeno

    , . .

    write() .

    >>> line1 = " ! \n"

    # line1 !.

    >>> keimeno.write(line1)

    # line1 . \n write .

    # keimeno write .

    >>> line2 = "Pythonistas.\n"

    >>> keimeno.write(line2)

    .

    >>> keimeno.close()

  • - '

    [ 105 ]

    write . , , . str:

    >>> x = 52

    >>> keimeno.write(str(x)).

    for .

    >>> keimeno = open('output.txt', r)

    open() "r", .

    read() readline(). , , :

    >>> keimeno.readline()

    7.2

    7.2.1 1

    song.txt. , .

    .

    .

    for i in range(telos);

    song=open("song.txt", "w")

    telos=int(input(" "))

    # .

    for i in range(telos):

    print (" ",i+1, )

    x = raw_input(" " )

    x=x + '\n'

    song.write(x)

    song.close()

  • - '

    [ 106 ]

    song=open("song.txt", "r")

    for line in song:

    print(line)

    a=line

    song.close()

    7.2.2 2

    hmerologio_2015.txt 2015 calendar.

    ) . IDLE Python. . hmerologio_2015.txt . ; .

    ) , hmerologio_2016 2016 .

    import calendar

    # calendar

    hmerologio=open("hmerologio_2015.txt", "w")

    # hmerologio_2015 hmerologio.

    hmerologio.write (" Python:\n\n")

    # .

    a= calendar.TextCalendar(calendar.SUNDAY).formatyear(2015, 2, 1, 1, 2)

    # a 2015, .

    hmerologio.write(a)

    ( ) , hmerologio

  • - '

    [ 107 ]

    hmerologio.write("\n\nPython: ...\n... .\n( l)")

    #

    hmerologio.close()

    # .

    #

    hmerologio=open("hmerologio_2015.txt","r")

    # r

    contents=hmerologio.read()

    # read() contents,

    print contents

    # ( 2015) . H .

    hmerologio.close()

    # , close()

    7.3

    ( ), , . , , Python .

    os ( os operating system). os.getcwd :

    >>> import os

    >>> cwd = os.getcwd()

    >>> print cwd /home/dinsdale

    cwd current working directory. /home/dinsdale, home dinsdale.

  • - '

    [ 108 ]

    7.4

    . . )

    my_list = [i**2 for i in range(1,11)] # 1 - 10 f = open("output.txt", "w") for item in my_list: f.write(str(item) + "\n") f.close()

    )

    f = open("bg.txt")

    f.closed

    # False

    f.close()

    f.closed

    # True

    C)

    >>> logfile = open('test.log', 'w')

    >>> logfile.write('test succeeded')

    >>> logfile.close()

    >>> print file('test.log').read()

    test succeeded

    >>> logfile = open('test.log', 'a')

    >>> logfile.write('line 2')

    >>> logfile.close()

    >>> print file('test.log').read()

    test succeededline 2

    D)

    g = open(' new_file ', 'w')

    g.write('A new file begins' )

    g.write(' ... today!\n')

  • - '

    [ 109 ]

    g.close( )

    E)

    f = open('input_file.txt')

    for line in f :

    print(line )

    1) ;

    2) - Python, ;

    3) ;

    4) ;

    5) ;

    6) ;

    . ., o , . (2013) Python, , .

    , ., (2010), Taspython. Python B, . Python , TasPython.

    Downey, A. (2012) Think Python, How to think like a computer scientist, O Reilly. http://www.greenteapress.com/thinkPython/. .

    Swaroop, C., H. (2013) A byte of Python, http://www.swaroopch.com/notes/Python/ Creative Commons Attributions ShareAlike 4.0 International License. Ubuntu. http://ubuntu-gr.org/ .

    .

    -

    , ( 21 ) , 9: , , ..., (..), 2015.

  • - '

    [ 110 ]

    Python, https://www.Python.org/ ( 10/07/2015)

    Berkeley, (2015), http://python.berkeley.edu/.

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

    .

  • - '

    [ 111 ]

    API

    8

  • - '

    [ 112 ]

    8. API

    (13 ) :

    , Application Program Interfaces (APIs) .

    8.1

    Python , . , Python . Application Programming Interfaces (APIs) .

    APIs Python matplotlib, SeaBorn Matplotlib ggplot ggplot2 R.

    Tkinter, Python (GUI).

    APIs , - (web crawler/spider) .

    , API, . , , API. .

    8.2 -

    (...) - (Human Computer Interaction HCI) -, () . , , , , .

  • - '

    [ 113 ]

    (user interface), . .

    " - (...)" , , . ( Association for Computer Machinery).

    , , , -.

    ... (Usability). ISO 9241, . :

    ()

    ( ).

    -

    (SAVE) (DELETE) , . , .

    . . , . . , , .

    . ;

  • - '

    [ 114 ]

    . () , .

    , ( ) ( ). .

    8.2.1

    , ' . . , , , . . , ..

    . . . Shneiderman (Shneiderman and Plaisant, 2005) :

    1. (consistency) :

    1) .

    2) .

    3) .

    4) .

    5) .

    6) .

    7) .

    2. (shortcut)

    1) .

    2) .

    3) .

    3. (informative feedback) .

  • - '

    [ 115 ]

    .. .

    4. "" -

    5.

    6.

    7.

    8. ( 72)

    : , , ;

    ;

    QWERTY ;

    (Norman 1990):

    .

    , , .

    , .

    , .

    , . .

    . .

    8.3 Tkinter GUI Python

    Python.

    import Tkinter as tk

    import tkMessageBox

  • - '

    [ 116 ]

    def showInformationBox():

    tkMessageBox.showinfo("Info","Nice Done")

    def showOkCancelBox():

    tkMessageBox.askokcancel("okCancel","Remove all System Files?")

    def showWarningBox():

    tkMessageBox.showwarning("warning","This is a warning")

    def showErrorBox():

    tkMessageBox.showerror("error","Critical System Error #00000")

    root = tk.Tk()

    root.title("Computer Science")

    message = tk.Label( root, text = "Introduction to Computer Science" )

    message.pack()

    message2 = tk.Label( root, text = "This is my first program" )

    message2.pack()

    buttonA = tk.Button( root, text = "Click here for Information", command =

    showInformationBox)

    buttonA.pack()

    buttonB = tk.Button( root, text = "Click here for Verification", command =

    showOkCancelBox)

    buttonB.pack()

    buttonC = tk.Button( root, text = "Click here for Warning", command =

    showWarningBox)

    buttonC.pack()

    buttonD = tk.Button( root, text = "Click here for Error Message", command =

    showErrorBox)

    buttonD.pack()

    root.mainloop()

  • - '

    [ 117 ]

    root = tk.Tk()

    root.title("Computer Science")

    Computer Science., . (Label) . ..

    buttonA = tk.Button( root, text = "Click here for Information", command =

    showInformationBox)

    - buttonA. Click here for Information, root showInformationBox . , , .

    pack root.mainLoop() .

    Tkinter Python.

    8.4

    8.4.1 1

    Beautiful Soup http://www.crummy.com/software/BeautifulSoup/

    8.4.2 2

    matplotlib http://matplotlib.org/examples. , , , , .. ,

  • - '

    [ 118 ]

    8.4.3 3

    matplotlib, Python , , :

    8.4.4 4:

    , Beautiful Soup. Python, Yahoo Finance Scraper.

    http://www.Pythoncentral.io/Python-beautiful-soup-example-yahoo-finance-

    scraper/

    / , scrapy, Python lxml

    http://docs.Python-guide.org/en/latest/scenarios/scrape/

    8.4.5 5:

    7 ( ) Tkinter, testRectangle.py.

    8.4.6 6:

    , Python. http://www.pygame.org project . . projects .

  • - '

    [ 119 ]

    ;

    ;

    ;

    ;

    Application Programming Interfaces (APIs). Python.

    . (2000) , . .

    Ben Shneiderman and Catherine Plaisant. Designing the User Interface. Pearson

    Education, Boston, 4th edition, 2005

    Donald A. Norman. The Design of Everyday Things. Doubleday/Currency, New

    York, NY, 1990. First published as The Psychology of Everyday Things.

    (2005), , . , http://cgi.di.uoa.gr/~ys08/EAM_simeiwseis.pdf ( 2015)

    Levitin, Anany (2007), The Design & Analysis of Algorithms. Pearson Education.

    Swaroop, C., H. (2013) A byte of Python, http://www.swaroopch.com/notes/Python/ Creative Commons Attributions ShareAlike 4.0 International License. Ubuntu. http://ubuntu-gr.org/ .

    , ( 21 ) , 9: , , ..., (..), 2015

    Python,

    https://pypi.Python.org/pypi

    http://matplotlib.org/users/pyplot_tutorial.html

    http://stanford.edu/~mwaskom/software/seaborn/

    https://pypi.Python.org/pypi/ggplot

    http://blog.yhathq.com/posts/ggplot-for-Python.html

  • - '

    [ 120 ]

    http://bokeh.pydata.org/

    Python for Data Analysis

    http://dl.e-book-free.com/2013/07/Python_for_data_analysis.pdf

    Python Scientific Lecture Notes

    http://scipy-lectures.github.io/

    Google Python

    https://code.google.com/p/google-visualization-Python/

    Python Beautiful Soup Example: Yahoo Finance Scraper

    http://www.Pythoncentral.io/Python-beautiful-soup-example-yahoo-finance-

    scraper/

    Beautiful Soup

    http://www.crummy.com/software/BeautifulSoup/

    http://www.gregreda.com/2013/03/03/web-scraping-101-with-Python/

    http://scrapy.org/

    Tkinter Python

    http://www.Python-course.eu/Python_tkinter.php

    https://wiki.Python.org/moin/TkInter