Week 4 Slides
Week 4 Slides
Amirsina Eskandarifar
Review
With what we have learnt so far, we can write any program and
implement any logic or algorithm!
questions
Break and Continue
For example:
Write a program to search for a character in the
given string, if it has the character print true.
Otherwise, false!
Break and Continue
For example:
Write a program to take both a sentence and a
character. Then, print words with that character?
Functions
𝑎,𝑏
𝑦
Functions
Python has some built-in functions, like: max, min, sum, avg, string
functions, type, print, list, int, …
Each one of these is just a block of code (including some basic logic)
for programmers to make their life easier!
Functions in Python
Input
arguments
def name_of_function(a , b , c):
return a**2
print(power_func())
Functions:
Difference between return and print?!
Write a function to take two numbers and return the summation of
them?
return a + b print(a + b)
add_func(1,2) add_func(1,2)
List_1 = [1,2,3]
List_2 = [4,5,6]
Then return: [4,10,18]
List_1 = [1,2,3]
List_2 = [4,5,6,7]
Then don’t return anything and print: error!
Sort Algorithms:
Bubble, Selection, and Insertion
Sorts
There is an array of number, and we want to sort them
1 9 2 8 5 4 3
https://www.youtube.com/watch?v=JU767SDMDvA
https://www.youtube.com/watch?v=g-PGLbMth_g
https://www.youtube.com/watch?v=xli_FI7CuzA