OpenEDG Python Institute Fulda
OpenEDG Python Institute Fulda
April 2018
Yes
You can find
me in this
picture!
© 2016
2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
Agenda
02 04
Overview of the
How to make your Programming Essentials
teaching job easier. In Python course
01 03
What is Python actually
make labs attractive and
used for?
easy.
We will do the lab now!
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
Education as the process
jobs.thelocal.com
01 03
For beginners with little or no Accessed online with no
prior knowledge of special equipment or
programming. system requirements.
02
Designed to be a full-semester 04
course: 5 modules, 5 quizzes, 5 Instructor-led training
module assessments, 30+ lab offered at no cost.
exercises, 2 summary tests,
and 1 final test.
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 9
The course and the lab online
© 2016
2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 10
How to start your adventure
with Python?
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
Please, enter our site:
http://workshop.pythoninstitute.org
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 12
Agenda
1 Problem 1: The strange plant
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 13
What is a variable?
A variable is a named container.
a number:
1
3.1415
a string:
problem "This is a string"
#1 'This is a string, too'
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 15
How to output a value?
variable = 123
print(1)
print("This is a string")
problem print(variable)
#1
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 16
How to input a value?
var1 = input()
var2 = input('Input a word')
problem
#1
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 17
How to input a number?
howmany = int(input())
howmuch = float(input())
problem
#1
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 18
How to check a variable?
if variable==1: print('equal')
problem
#1
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 19
How to check a variable?
if variable==1: print('equal')
else: print('sorry')
problem
#1
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 20
OK,
now we can deal with
problem #1
problem
#1
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 21
How to evaluate an
expression's value?
var = a + b
problem
#2
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 22
How to evaluate
expression's value?
var = a * b
problem
#2
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 23
How to evaluate
expression's value?
var = a - b
problem
#2
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 24
How to evaluate
expression's value?
var = a / b
problem
#2 ...but, please, don't try do divide by zero
(unless you want to cause a little disaster)
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 25
How to evaluate an
expression's value?
var = (a * (1 + b)) / (b – a)
problem
#2
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 26
OK,
now we can approach
problem #2
problem
#2
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 27
How to repeat execution
of any part of your code?
for v in range(1,5):
print(v)
1
problem 2
#3 3
4
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 28
How to repeat execution
of any part of your code?
for v in range(3):
print(v)
0
problem 1
#3 2
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 29
OK,
now we can launch
problem #3
problem
#3
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 30
How letters are stored
within the computer
memory?
problem
#4
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 31
How to get an ASCII
code of a letter?
letter = 'A'
code = ord(letter)
print(code)
problem
#4 (Note: it will print 65 to the console –
check it yourself) © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 32
How to get a letter stored
as a given ASCII code?
code = 66
letter = chr(code)
print(letter)
problem
#4 (Note: it will print B to the console – check it
yourself) © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 33
How to traverse through all
the letters of a string?
string = 'abc'
for c in string:
print(c)
problem
#4 (Note: it will print a b c to the console)
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 34
How to check if a character
is actually an uppercase
letter?
char1 = 'A'
char2 = 'z'
print(char1.isupper()) # True
problem
print(char2.isupper()) # False
#4
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 35
How to control the output?
print('IULIUS')
print('CAESAR')
IULIUS
CAESAR
problem
#4
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 36
How to control the output?
print('IULIUS', end='')
print('CAESAR')
IULIUSCAESAR
problem
#4
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 37
OK,
we are ready to cope with
problem #4
problem
#4
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 38
How to collect more than
one value inside one
variable?
problem
#5
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 41
How to initialize letters'
counters?
freqdict = {}
for c in range(ord('A'),ord('Z')+1):
freqdict[chr(c)] = 0
problem
#5
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 42
How to count all letters?
for c in text:
if c.isalpha():
freqdict[c] += 1
problem
#5
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 43
How to sort letters by their
frequencies?
transcodedict = {}
for c in sorted(freqdict, key=lambda x : freqdict[x], reverse=True):
transcodedict[c] = freqstr[0]
freqstr = freqstr[1:]
problem
#5
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 44
How to sort letters by their
frequencies?
transcodedict = {}
for c in sorted(freqdict, key=lambda x : freqdict[x], reverse=True):
transcodedict[c] = freqstr[0]
freqstr = freqstr[1:]
problem
#5
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 45
OK,
let's break the code!
problem
#5
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 46
Q&A
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 47