Top Banner
Maciek Wichary, Sławek Wernikowski, OpenEDG Python Institute April 2018 2018, Fulda, Germany Nationaler Akademietag in Fulda 2018 Python
48

Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

Nov 02, 2019

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

Maciek Wichary, Sławek Wernikowski, OpenEDG Python Institute

April 2018

2018, Fulda, Germany

Nationaler Akademietag in Fulda 2018

Python

Page 2: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

2© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

My very first CCNA group back in 2002

All of my students have great jobs now.

Yes

You can find

me in this

picture!

Page 3: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

3© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Agenda

Why Python? Use of Python Overview EDUBE

01

How to make your

teaching job easier. 02Overview of the

Programming Essentials

In Python course

What is Python actually

used for? 03A very important tool to

make labs attractive and

easy.

We will do the lab now!

04

Page 4: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

Education as the process

Start Lectures, labs, quizes, chapter assesments

jobs.thelocal.com

Page 5: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

What is Python actually used for?

Battlefield 2, Battlefield 2142 and Battlefield Heroes

All the games use Python for logic and server controls

They were all written, to

a greater or lesser

extent, in Python.

Page 6: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

Other examples

• Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle,

TwistedMatrix)

• 3D CAD/CAM (FreeCAD, Fandango, Blender, Vintech RCAM)

• Enterprise Applications (Odoo, Tryton, Picalo, LinOTP 2, RESTx)

• Image Applications (Gnofract 4D, Gogh, imgSeek, MayaVi, VPython)

• Mobile Applications (Aarlogic C05/3, AppBackup, Pyroute)

• Office Applications (calibre, faces, Notalon, pyspread)

• Personal Information Managers (BitPim, Narval, Prioritise, Task Coach,

WikidPad)

Page 7: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

Generally, Python is a great choice for:

• Web and Internet development (e.g., Django and Pyramid frameworks, Flask and Bottle

micro-frameworks)

• Scientific and numeric computing (e.g., SciPy – a collection of packages for the purposes of

mathematics, science, and engineering; Ipython – an interactive shell that features editing

and recording of work sessions)

• Education (it’s a brilliant language for teaching programming! And that’s why we’re

offering this course to you!)

• Desktop GUIs (e.g., wxWidgets, Kivy, Qt)

• Software Development (build control, management, and testing – Scons, Buildbot, Apache

Gump, Roundup, Trac)

• Business applications (ERP and e-commerce systems – Odoo, Tryton)

Page 8: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

Python’s strength is not about its speed. It is all

about simplicity and readability.

Page 9: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

9© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

OverviewPCAP | Programming Essentials In Python

01For beginners with little or no

prior knowledge of

programming.

02

03Accessed online with no

special equipment or

system requirements.

04Instructor-led training

offered at no cost.

Designed to be a full-semester

course: 5 modules, 5 quizzes, 5

module assessments, 30+ lab

exercises, 2 summary tests,

and 1 final test.

Page 10: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

10© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 10© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

The course and the lab online

Page 11: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

11© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to start your adventurewith Python?

Page 12: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

12© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Please, enter our site:

http://workshop.pythoninstitute.org

Page 13: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

13© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Agenda

Problem 1: The strange plant

Problem 2: Paying our dues

Problem 3: Indians' investments

1

2

3

Problem 4: How did Caesar write his mails?4

Problem 5: How to read Caesar's mails?5

Page 14: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

14© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

What is a variable?A variable is a named container.

You can put a single value or even a

couple of different values into such a

container.

Some words could not be used to

name variables and… doesn't matter.

variable = value

variable = expression

problem

#1

Page 15: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

15© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

What is a value?To make things clear, we can say that a

value can be:

a number:

1

3.1415

a string:

"This is a string"

'This is a string, too'problem

#1

Page 16: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

16© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to output a value?

If you want to output a value to the

screen/console, you use print()

variable = 123

print(1)

print("This is a string")

print(variable)problem

#1

Page 17: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

17© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to input a value?

If you want to input a value from the

keyboard, you use input()

Note: the input is always a string!

var1 = input()

var2 = input('Input a word')problem

#1

Page 18: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

18© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to input a number?

If you want to input a number, you need

to convert it from a string – int() or

float() will do it for you.

howmany = int(input())

howmuch = float(input())

problem

#1

Page 19: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

19© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to check a variable?

If you want to check if a variable contains

a speficic value, you can ask about it:

if variable==1: print('equal')

problem

#1

Page 20: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

20© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to check a variable?

You can also do something different if the

check fails:

if variable==1: print('equal')

else: print('sorry')

problem

#1

Page 21: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

21© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

OK,

now we can deal with

problem #1

problem

#1

Page 22: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

22© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to evaluate an

expression's value?

Python knows arithmetic – you can rely

on it.

Python can add numbers:

var = a + b

problem

#2

Page 23: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

23© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to evaluate

expression's value?

Python knows arithmetic – you can rely

on it.

Python can multiply numbers:

var = a * b

problem

#2

Page 24: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

24© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to evaluate

expression's value?

Python knows arithmetic – you can rely

on it.

Python can subtract numbers:

var = a - b

problem

#2

Page 25: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

25© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to evaluate

expression's value?

Python knows arithmetic – you can rely

on it.

Python can divide numbers:

var = a / b

...but, please, don't try do divide by zero (unless you want to cause a little disaster)

problem

#2

Page 26: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

26© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to evaluate an

expression's value?

Your expression can be as complex as

you need – you can use parentheses,

too.

var = (a * (1 + b)) / (b – a)

problem

#2

Page 27: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

27© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

OK,

now we can approach

problem #2

problem

#2

Page 28: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

28© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to repeat execution

of any part of your code?

for v in range(1,5):

print(v)

problem

#3

1

2

3

4

Page 29: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

29© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to repeat execution

of any part of your code?

for v in range(3):

print(v)

problem

#3

0

1

2

Page 30: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

30© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

OK,

now we can launch

problem #3

problem

#3

Page 31: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

31© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How letters are stored

within the computer

memory?

They are stored as numbers, based on

ASCII standard.

problem

#4

Page 32: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

32© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to get an ASCII

code of a letter?

You need to use ord()

letter = 'A'

code = ord(letter)

print(code)

(Note: it will print 65 to the console –

check it yourself)

problem

#4

Page 33: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

33© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to get a letter stored

as a given ASCII code?

You need to use chr()

code = 66

letter = chr(code)

print(letter)

(Note: it will print B to the console – check it

yourself)

problem

#4

Page 34: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

34© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to traverse through all

the letters of a string?

You can use for.

string = 'abc'

for c in string:

print(c)

(Note: it will print a b c to the console)problem

#4

Page 35: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

35© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to check if a character

is actually an uppercase

letter?

char1 = 'A'

char2 = 'z'

print(char1.isupper()) # True

print(char2.isupper()) # Falseproblem

#4

Page 36: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

36© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to control the output?

print('IULIUS')

print('CAESAR')

problem

#4

IULIUS

CAESAR

Page 37: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

37© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to control the output?

print('IULIUS', end='')

print('CAESAR')

problem

#4

IULIUSCAESAR

Page 38: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

38© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

OK,

we are ready to cope with

problem #4

problem

#4

Page 39: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

39© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to collect more than

one value inside one

variable?

You can use a list.

list = [] # list is empty

list.append(1) # list has 1 elem

list.append(2) # list has 2 elems

print(list) # [ 1, 2 ]problem

#5

Page 40: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

40© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to collect more than

one value inside one

variable?

You can use a dictionary.

dict = {} # dict is empty

dict['a'] = 1 # 1st key/elem

dict['b'] = 2 # 2nd key/elem

print(dict) # {'a': 1, 'b': 2}problem

#5

Page 41: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

41© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to read the content of

a file into a variable?

with open('filename') as file:

text = file.read();

problem

#5

Page 42: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

42© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to initialize letters'

counters?

freqdict = {}

for c in range(ord('A'),ord('Z')+1):

freqdict[chr(c)] = 0

problem

#5

Page 43: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

43© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to count all letters?

for c in text:

if c.isalpha():

freqdict[c] += 1

problem

#5

Page 44: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

44© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to sort letters by their

frequencies?

problem

#5

transcodedict = {}

for c in sorted(freqdict, key=lambda x : freqdict[x], reverse=True):

transcodedict[c] = freqstr[0]

freqstr = freqstr[1:]

Page 45: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

45© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How to sort letters by their

frequencies?

problem

#5

transcodedict = {}

for c in sorted(freqdict, key=lambda x : freqdict[x], reverse=True):

transcodedict[c] = freqstr[0]

freqstr = freqstr[1:]

Page 46: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

46© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

OK,

let's break the code!

problem

#5

Page 47: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,

47© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Q & A

Page 48: Python - it-bildungsnetz.de · Other examples • Internet Applications (BitTorrent, Jogger Publishing Assistant, TheCircle, TwistedMatrix) • 3D CAD/CAM (FreeCAD, Fandango, Blender,