SlideShare a Scribd company logo
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Python programming
intermediate course
Created by Alexander Galkin aka Alaudo
published under Creative Common License
Course outline
• Session 1: Leveling the ground (basic Python)
• Session 2: Strings and collections
• Session 3: Functions, Dictionaries etc..
CONTROL FLOW AND VARS
Session 1
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Control flow
print(“hello”)
print(“My name is Alex”)
print(“I am your new master”)
print(“This is command #4”)
Variables
• Variables are basically boxes that you can put
stuff in
• They store the values you assign them
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Variables
print("Hello, I am python, your servant")
master = input("What is your name, master? ")
print("I am glad to welcome you")
print(master)
print("my master")
Types
• A type is the kind of value that a value (and
variable) can be
• There are numerous kinds of types
• String, Integer, Boolean are examples
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Types
word = "Word"
print(type(word))
number = 3
print(type(number))
fraction = 2/7
print(type(fraction))
print(fraction)
equation = 4 > 8
print(type(equation))
print(equation)
Boolean Operators
• These are logic checks that you can use to
determine when actions should happen
• and, or, != (not equal), == (equal to),
> (greater than), < (less than), >= (greater than
or equal to), <= (less than or equal to), and
True/False
Important
• In computers the equal sign can mean
different things!!!
• In Python
=  assignment (let var a take the value b)
==  comparison (if var a equals var b)
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
variable1 = 1
variable2 = 5
variable3 = 5
variable1 == variable2
variable1 != variable2
variable1 < variable2
variable1 > variable2
variable1 <= variable2
variable2 >= variable3
variable1 < variable2 and
variable2 > variable3
variable1 < variable2 or
variable2 > variable3
False
True
True
False
True
True
False
True
What can we compare?
• Numbers ( 2, 3, 5, 5.5, 7.5, 8 )
• Strings (“alex”, “bert”, “cindy”)
• Dates and times
(for all orderable types – two values)
• Numbers and strings?
• Numbers and dates/times?
If/Else Statement
• A statement that will run one set of code if a
condition is met, and the other set of code if a
condition is not met.
• Condition is written as a Boolean expression
that returns True or False
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
If/Else
person1 = input("What is the first name? ")
person2 = input("What is the second name? ")
if person1 > person2:
print(person1)
print("has won")
else:
print(person2)
print("has won")
Elif
• You can chain if/else statements together with
elif
• This allows you to check for multiple
conditions
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
If/Else/Elif
person1 = input("What is the first name? ")
person2 = input("What is the second name? ")
if person1 > person2:
print(person1)
print("has won")
elif person1 == person2:
print("friendship")
print("has won")
else:
print(person2)
print("has won")
While Loops
• Loop while a condition is met
• Runs the code inside of them every time you
iterate
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
while
answer = input("Do you want to play a game? ")
while answer == "yes":
person1 = input("What is the first name? ")
person2 = input("What is the second name? ")
if person1 > person2:
print(person1)
print("has won")
elif person1 == person2:
print("friendship")
print("has won")
else:
print(person2)
print("has won")
answer = input("Do you want to play a game? ")
For Loops
• Loop over a given range/set/list
• Run the code inside of them every time you
iterate
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
for in range
answer = int(input("How many times do you want to play? "))
for i in range(0,answer):
person1 = input("What is the first name? ")
person2 = input("What is the second name? ")
if person1 > person2:
print(person1)
print("has won")
elif person1 == person2:
print("friendship")
print("has won")
else:
print(person2)
print("has won")
STRINGS AND COLLECTIONS
Session 2
https://github.com/alaudo/coderdojo-python
http://enigmacode.azurewebsites.net/
Recap from last session
age = input("What is your age? ")
if age =< 10:
print("You are below 10!")
if age = 10:
print("You are exactly 10!")
if age => 10:
print("Your are above 10!")
How many errors can you find here?
Recap from last session
m = 3
s = 0
for i in range (1,m):
s = s + i
print(s)
What number will this program print?
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
while
answer = input("Do you want to play a game? ")
while answer == "yes":
person1 = input("What is the first name? ")
person2 = input("What is the second name? ")
if person1 > person2:
print(person1)
print("has won")
elif person1 == person2:
print("friendship")
print("has won")
else:
print(person2)
print("has won")
answer = input("Do you want to play a game? ")
How to remove the duplicate line?
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Advanced loops
• break
• continue
• pass
while True:
answer = input("Do you want to play a game? ")
if (answer != "yes"):
break
else:
person1 = input("What is the first name? ")
person2 = input("What is the second name? ")
if person1 > person2:
print(person1)
elif person1 == person2:
print("friendship")
else:
print(person2)
print("has won")
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Strings: what do we now?
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Strings: what do we now and what
don’t?
• Get with “input”
command
• Compare as numbers
• Compare with “==“ and
“!=“
• Print with “print”
command
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Strings: what should we know?
• Get with “input”
command
• Compare as numbers
• Compare with “==“ and
“!=“
• Print with “print”
command
• How to check if string is
empty?
• How to get string length?
• How to get a part of a
string?
• How to replace one
symbol with another?
• How to reverse string?
• How to split string?
• How to stich many strings
together?
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Strings & math
• What happens if we:
o string1 + string2
o string1 – string2
o string1 * 10
o string2 / 5
o string3 % 5
• How can we:
stitch strings
remove part of string
copy string
format string
How to test for empty string?
text = input("Enter something ")
if (text):
print("This text is not empty")
else:
print("This text is EMPTY")
What about just spaces in the string?
How find how long a string is?
text = input("Enter something ")
print (len(text))
But how to print the text WITH numbers?
Pretty printing in Python?
print("My length is " + str(len("My length is")))
print("My favorite programming language is %s " % "python")
print("{} and {} are best friends".format("me", "my papa"))
print("My name is {name} and I am {age} years old".format(name = "Alex", age = 37))
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Strings: what should we know?
• Get with “input”
command
• Compare as numbers
• Compare with “==“ and
“!=“
• Print with “print”
command
• How to check if string is
empty?
• How to get string length?
• How to get a part of a
string?
• How to replace one
symbol with another?
• How to reverse string?
• How to split string?
• How to stich many strings
together?
Pretty printing in Python?
print("I am a good programmer".replace("good","not really good"))
print("<***>".join(["one","two","three","four"]))
print(''.join(reversed("I am a good string")))
print("I am a good athlete".split(" "))
Lists
• A list is a container that holds other
objects/values
• A list can be as large as you need it to be
• You can access the values inside a list at any
time as long as you have the list
Hidden lists
for i in range(0,10):
print(i)
print(list(range(0,10)))
txt = "pizza is no longer hot"
for i in txt:
print(i)
print(list(txt))
Lists, they are everywhere… 
Browsing lists
a = "Jingle bells, Jingle bells
Jingle all the way Oh what fun it
is to ride"
print(a[0])
print(a[1])
print(a[0:10])
print(a[0:10:2])
print(a[::3])
print(a[::-1])
Browsing lists (2)
a = "Jingle bells, Jingle bells
Jingle all the way Oh what fun it
is to ride“
a = a.split(“ “)
print(a[0])
print(a[1])
print(a[0:10])
print(a[0:10:2])
print(a[::3])
print(a[::-1])
CoderDojo: Intermediate Python programming course
ASCII manipulations
a = "Jingle bells, Jingle bells Jingle all the way
Oh what fun it is to ride"
l = []
for i in a:
l.append(ord(i))
print(l)
m = []
for t in l:
m.append(t + 2)
print(m)
v = []
for k in m:
v.append(chr(k))
print(''.join(v))
List comprehensions
a = "Jingle bells, Jingle bells Jingle all the way
Oh what fun it is to ride"
l = [ord(i) for i in a]
print(l)
m = [t + 2 for t in l]
print(m)
v = [chr(k) for k in m]
print(''.join(v))
Challenge begins!! 
https://github.com/alaudo/coderdojo-python
http://enigmacode.azurewebsites.net/
FUNCTIONS, DICTIONARIES ETC
Session 3
Trying to decode…
PPhhoottoonnss hhaavvee nneeiitthheerr mmoorraallss nnoorr
vviissaass..
How can we decode this?
Trying to decode…
PPhhoottoonnss hhaavvee nneeiitthheerr mmoorraallss nnoorr
vviissaass..
text = "PPhhoottoonnss hhaavvee nneeiitthheerr mmoorraallss nnoorr vviissaass.."
print(text[::2])
Trying to decode…
What about this?
IIIInnnnssssiiiiddddeeee eeeevvvveeeerrrryyyy ssssmmmmaaaalll
lllll pppprrrroooobbbblllleeeemmmm iiiissss aaaa bbbbiiiigggg
oooonnnneeee ttttrrrryyyyiiiinnnngggg ttttoooo ggggeeeetttt
ggggoooovvvveeeerrrrnnnnmmmmeeeennnntttt ffffuuuunnnnddd
diiiinnnngggg....
Trying to decode…
How can we skip the burden of writing the same code again and again?
IIIInnnnssssiiiiddddeeee eeeevvvveeeerrrryyyy ssssmmmmaaaalll
lllll pppprrrroooobbbblllleeeemmmm iiiissss aaaa bbbbiiiigggg
oooonnnneeee ttttrrrryyyyiiiinnnngggg ttttoooo ggggeeeetttt
ggggoooovvvveeeerrrrnnnnmmmmeeeennnntttt ffffuuuunnnnddd
diiiinnnngggg....
text =
"IIIInnnnssssiiiiddddeeee eeeevvvveeeerrrryyyy ssssmmmmaaaallllllll pppprrrroooobbbbl
llleeeemmmm"
print(text[::4])
Functions
• Functions are like tools: you can re-use the same tool
in many situations to solve similar problems
• Functions take input – something they are applied to
– and return the result back
• In addition to input the functions can also take any
number of parameters to specify what and how the
function should be applied
Functions as reusable components
PPhhoottoonnss hhaavvee nneeiitthheerr mmoorraallss nnoorr
vviissaass..
We parameterize functions instead of re-writing code
def dedouble(text, count):
return text[::count]
print(dedouble(“PPhhoottoonnss hhaavvee”,2))
print(dedouble(“IIIInnnnssssiiiiddddeeee”,4))
Further decoding
.ti esu ot tnaw lliw toidi na ylno dna esu nac
toidi na metsys a ngiseD
What about this?
Further decoding
.ti esu ot tnaw lliw toidi na ylno dna esu nac
toidi na metsys a ngiseD
def palindrome(text):
return text[::-1]
More advanced
it. invent is do can we All all. at future the predict really can't We
What about this?
More advanced
it. invent is do can we All all. at future the predict really can't We
Well done!!
def yoda(text):
return " ".join(text.split(" ")[::-1])
Further and further
s'tI suoregnad ot eb thgir nehw eht tnemnrevog si .gnorw
What about this?
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
List: recap
1. How to create an
empty List?
2. How to add element to
a list?
3. How to test if element
is in the list?
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
List: recap
1. How to create an
empty List?
2. How to add element to
a list?
3. How to test if element
is in the list?
1. lst = []
2. lst.append(elem)
3. if elem2 in lst:
Further and further
s'tI suoregnad ot eb thgir nehw eht tnemnrevog si .gnorw
def mirror(text):
words = text.split(" ")
nwords = []
for w in words:
nw = w[::-1]
nwords.append(nw)
return " ".join(nwords)
Mastering the Ceasar shift cipher
kpfkhhgtgpeg yknn egtvckpna dg vjg fqyphcnn qh ocpmkpf, dwv yjq ectgu?
How to crack this?
In-place condition aka ternary operator
• If takes a complete line – sometimes it is too
much
• You can reverse it for in-place condition
a = 4
b = 3
print (a if a > b else b)
Mastering the Ceasar shift cipher
kpfkhhgtgpeg yknn egtvckpna dg vjg fqyphcnn qh ocpmkpf, dwv yjq ectgu?
stoplist = [ ' ', ',', '?']
def ceasar(text, shift):
return "".join([t if (t in stoplist) else chr(ord('a') + (ord(t) - ord('a') + shift + 26) % 26 ) for t in text])
Simple substitution cipher
тhe$e @Яe que$т!0п$ f0Я @cт!0п, п0т $pecu1@т!0п, шh!ch !$ !d1e.
How to optimize replace here?
Dictionary
• Like a usual dictionary
– Has a key – e.g. the glossary word we look for
– Contains value – e.g. the explanation for word
• It helps to associate things pairwise
• Most often used to find a value for a key, but
can be reversed if needed (costy!)
• Other names: hash, hashtable, map
https://github.com/alaudo/coderdojo-pythonhttp://enigmacode.azurewebsites.net/
Dictionary operations
1. How to create a d?
2. How to add an
element?
3. How to check for
element?
4. How to retrieve an
element?
1. dct = { ‘a’ : ‘b’, ‘b’ : ‘c’}
2. dct[‘v’] = ‘w’
3. if (elem in dct):
4. dct[‘b’]
Simple substitution cipher
тhe$e @Яe que$т!0п$ f0Я @cт!0п, п0т $pecu1@т!0п, шh!ch !$ !d1e.
def subst(text):
s = { 'т' : 't', '$' : 's', '@' : 'a', '!' : 'i', 'Я' : 'r', '1' : 'l', 'ш' : 'w', '0' : 'o', 'п' : 'n'}
return "".join([t if not(t in s.keys()) else s[t] for t in text ])
BUILDING DECODING SOFTWARE
Total recap
Decoding assistant
> message .eldi si hcihw ,noitaluceps ton ,noitca
rof snoitseuq era esehT
Message [0]: “.eldi si hcihw ,noitaluceps ton
,noitca rof snoitseuq era esehT”
>apply palindrome 0
Message [0]: “sdsdf”
Applied k

More Related Content

ODP
An Intro to Python in 30 minutes
PDF
Introduction to python
PPTX
Learn python in 20 minutes
ODP
Programming Under Linux In Python
PDF
Python in 90 minutes
PDF
Python for Linux System Administration
PDF
Python Tutorial
PDF
Functional Programming & Event Sourcing - a pair made in heaven
An Intro to Python in 30 minutes
Introduction to python
Learn python in 20 minutes
Programming Under Linux In Python
Python in 90 minutes
Python for Linux System Administration
Python Tutorial
Functional Programming & Event Sourcing - a pair made in heaven

What's hot (20)

PDF
Real world gobbledygook
PPTX
Poly-paradigm Java
PPTX
python beginner talk slide
PPTX
Python Workshop
PPT
Scala presentation by Aleksandar Prokopec
KEY
groovy & grails - lecture 3
ODP
Naïveté vs. Experience
PPTX
R. herves. clean code (theme)2
KEY
Concurrent programming with Celluloid (MWRC 2012)
PDF
Odessapy2013 - Graph databases and Python
PDF
tictactoe groovy
PDF
Monads asking the right question
PDF
What can be done with Java, but should better be done with Erlang (@pavlobaron)
PDF
Designing with Groovy Traits - Gr8Conf India
PDF
Don't do this
PDF
Clojure for Java developers - Stockholm
ODP
Turtle Graphics in Groovy
PDF
Python 101 1
KEY
Writing your own programming language to understand Ruby better - Euruko 2011
PDF
Vim Script Programming
Real world gobbledygook
Poly-paradigm Java
python beginner talk slide
Python Workshop
Scala presentation by Aleksandar Prokopec
groovy & grails - lecture 3
Naïveté vs. Experience
R. herves. clean code (theme)2
Concurrent programming with Celluloid (MWRC 2012)
Odessapy2013 - Graph databases and Python
tictactoe groovy
Monads asking the right question
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Designing with Groovy Traits - Gr8Conf India
Don't do this
Clojure for Java developers - Stockholm
Turtle Graphics in Groovy
Python 101 1
Writing your own programming language to understand Ruby better - Euruko 2011
Vim Script Programming
Ad

Similar to CoderDojo: Intermediate Python programming course (20)

PPTX
Python Workshop - Learn Python the Hard Way
PPTX
P2 2017 python_strings
PPTX
2015 bioinformatics python_strings_wim_vancriekinge
PPTX
Kotlin coroutines and spring framework
PDF
PDF
Learn 90% of Python in 90 Minutes
PPTX
Basic Python Programming: Part 01 and Part 02
PDF
Crystal presentation in NY
PPTX
Functions, List and String methods
PPTX
The document discusses for loops in Python. It explains that for loops are us...
PPTX
Python in 30 minutes!
PDF
Learn Python 3 for absolute beginners
PDF
Happy Go Programming
PDF
Intro to Python
KEY
Clojure Intro
PPTX
GE8151 Problem Solving and Python Programming
ODP
Dynamic Python
PDF
Sessisgytcfgggggggggggggggggggggggggggggggg
PPTX
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Workshop - Learn Python the Hard Way
P2 2017 python_strings
2015 bioinformatics python_strings_wim_vancriekinge
Kotlin coroutines and spring framework
Learn 90% of Python in 90 Minutes
Basic Python Programming: Part 01 and Part 02
Crystal presentation in NY
Functions, List and String methods
The document discusses for loops in Python. It explains that for loops are us...
Python in 30 minutes!
Learn Python 3 for absolute beginners
Happy Go Programming
Intro to Python
Clojure Intro
GE8151 Problem Solving and Python Programming
Dynamic Python
Sessisgytcfgggggggggggggggggggggggggggggggg
Python Interview Questions | Python Interview Questions And Answers | Python ...
Ad

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
cuic standard and advanced reporting.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
KodekX | Application Modernization Development
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
cuic standard and advanced reporting.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
20250228 LYD VKU AI Blended-Learning.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Chapter 3 Spatial Domain Image Processing.pdf
Approach and Philosophy of On baking technology

CoderDojo: Intermediate Python programming course