May, 2022 - François HU
Master of Science - EPITA
This lecture is available here: https://curiousml.github.io/
These exercices are considered "easy" exercices.
Create a function add_more
, that produces the following results:
>>> add_more(1, 1)
3
>>> add_more(1, -1)
1
>>> add_more(5, 0)
6
Crate a function create_list
, that produces the following results:
>>> create_list(5)
[1, 4, 9, 16, 25]
>>> create_list(10)
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
>>> create_list(-1)
[]
Create a function add_lists
that produces the following results (we assume that the two lists have same length)
>>> add_lists([1, 2, 3], [-1, 2, -2])
[0, 4, 1]
>>> add_lists([1, 0, 0], [-1, 2, -2])
[0, 2, -2]
>>> add_lists([1, 0, 0], [0, 1, 1])
[1, 1, 1]
Create a function add_lists_improved
that produces the following results (we don't assume that the two lists have same length)
>>> add_lists_improved([1, 2, 3], [-1, 2, -2])
[0, 4, 1]
>>> add_lists_improved([1, 2, 3], [-1, 2, -2, 1, 2])
[0, 4, 1, 1, 2]
>>> add_lists_improved([1, 0, 0, -1, 0], [0, 1, 1])
[1, 1, 1, -1, 0]
We have the following dictionary students
(don't forget to execute the cell):
# DON'T MODIFY THIS PROGRAM, JUST EXECUTE IT
students = {'Name': ['Arthur',
'Marcial',
'Margaux',
'François',
'Julie',
'Sophie',
'Alex',
'Christine'
],
'Grade': [8, 2, 15, 3, 7, 10, 11, 16]}
In the field Name
of the dictionary, add (e.g. use append
command) a new name "Sacha"
.
In the field Grade
of the dictionary, add (e.g. use append
command) a new grade 19
.
Let us continue working with the previous dictionary students
.
Upgrade
in the dictionary. The associated value is the lists students["Grade"]
where each value is incremented by 1.
Create a function concatenate_str
that produces the following results:
>>> concatenate_str("I", "am")
I am
>>> concatenate_str("a", "student")
a student
>>> concatenate_str("of", "EPITA")
of EPITA
Do these exercices first with explicit loops and then without explicit loops.
arr1
.
[[ 1 2 3 4 5 6]
[ 7 8 9 10 11 12]
[13 14 15 16 17 18]
[19 20 21 22 23 24]
[25 26 27 28 29 30]
[31 32 33 34 35 36]]
arr1
the following submatrix. Name it subarr1
.
[[ 9 8 10 11]
[15 14 16 17]
[21 20 22 23]
[27 26 28 29]]