November, 2021 - updated on April, 2022 - François HU
Master of Science - EPITA
This lecture is available here: https://curiousml.github.io/
Create a list list_
which holds the values $[1, 4, 9, 16, 25, \dots, 400]$.
Example:
>>> list_[0]
1
>>> list_[10]
121
>>> list_[-1]
400
Create a function inter_in(l, i, j)
that swaps the values in position i
and j
of the list l
.
Remark: no need for the function to return an object !
Example:
>>> inter_in(list_, 0, 10)
>>> list_[0]
121
>>> list_[10]
1
>>> inter_in(list_, 0, 10)
>>> list_[0]
1
>>> list_[10]
121
inter_out(l, i, j)
that returns a copy of the list l
in which the values in positions i
and j
are swapped.
Example:
>>> clist = inter_out(list_, 0, 10)
>>> clist[0]
121
>>> clist[10]
1
>>> list_[0]
1
>>> list_[10]
121
Hint: Use the method copy
of the built-in object list
(lists are mutable).## WRITE IN THIS CELL YOUR CODE WITHOUT ANY ERRORS. YOU SHOULD GENERATE THE LIST: list_
## question 1
## WRITE IN THIS CELL YOUR CODE WITHOUT ANY ERRORS. YOU SHOULD GENERATE THE FUNCTION: inter_in
## question 2
## WRITE IN THIS CELL YOUR CODE WITHOUT ANY ERRORS. YOU SHOULD GENERATE THE FUNCTION: inter_out
## question 3
We have the following dictionary which contains students grade (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]}
The teacher wants to reajust the grades and decides to add 5 points to the grade of each student. For that purpose, follow the following steps:
students['Grade']
in a new list named ugrade
students
, add a new field named Ugrade
with ugrade
as an item.Even after the reajustment, some students have less than 10 points so therefore they need to do a rattrapage examination.
retake_examination
which contains the Name
, Grade
and Ugrade
of the students who need to retake the examination.## WRITE IN THIS CELL YOUR CODE WITHOUT ANY ERRORS. YOU SHOULD GENERATE THE LIST: ugrade
## question 1
## WRITE IN THIS CELL YOUR CODE WITHOUT ANY ERRORS. YOU SHOULD UPDATE THE DICITONARY: students
## question 2
## WRITE IN THIS CELL YOUR CODE WITHOUT ANY ERRORS. YOU SHOULD GENERATE THE DICITONARY: retake_examination
## question 3
signature(text)
which returns the string text
with " EPITA."
at the end.
Remark: be careful, we have a space and .
in the signature.Example:
>>> signature('Hello world!')
'Hello world! EPITA.'
>>> signature("Don't be late for the test.")
"Don't be late for the test. EPITA."
delete_signature(text)
which returns the string text
with " EPITA."
at the end deleted. If the substring " EPITA."
does not exist, then do nothing.
Example:
>>> delete_signature('Hello world! EPITA.')
'Hello world!'
>>> delete_signature("Don't be late for the test.")
"Don't be late for the test."
>>> delete_signature('Hello world! EPITA')
'Hello world! EPITA'
Hints: a string is a container where:text
with text[-7:]
;text
except the last 7 characters with text[:-7]
.## WRITE IN THIS CELL YOUR CODE WITHOUT ANY ERRORS. YOU SHOULD GENERATE THE FUNCTION: signature
## question 1
## WRITE IN THIS CELL YOUR CODE WITHOUT ANY ERRORS. YOU SHOULD GENERATE THE FUNCTION: delete_signature
## question 2