EXAMEN PYTHON
Exercice I : QCM (8 pts)
Cochez la bonne réponse.
1. What is the purpose of the file mode "rb" in Python?
a) Read text
b) Write binary
c) Read binary
d) Append binary
2. Which function checks if a file exists?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
3. What is the role of the with statement in file handling?
a) Open multiple files
b) Automatically close the file
c) Read binary files
d) Rename the file
4. In OOP, what is inheritance?
a) Creating many objects
b) One class acquiring attributes from another
c) Hiding data
d) Redefining methods
5. Ability of classes to implement the same method differently is called:
a) Encapsulation
b) Abstraction
c) Polymorphism
d) Inheritance
6. Which function creates a NumPy array from a list?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
7. How do you access the element in the 2nd row and 1st column of a NumPy array
arr?
a) arr[2][1]
b) arr[1][0]
c) arr[0][1]
d) arr[1][1]
8. Which Pandas function removes duplicate rows?
a) [Link]()
b) [Link]()
c) df.drop_duplicates()
d) [Link]()
Exercice II : Programmation Orientée Objet (6 pts)
1. Create a class named Employee with the following attributes:
● name
● salary
2. Add to the class:
● A constructor
● A method display() that prints employee information
3. Create a subclass Manager that:
● Inherits from Employee
● Has an additional attribute department
● Overrides the display() method
4. Create an object of the class Manager and display its information.
Exercice III : Pandas & Matplotlib (6 pts)
Consider the following DataFrame df:
Emp_ID Name Dept Salary Status
100 Ali IT 12000 Regular
101 Ahmed Financ 16000 Regular
e
102 Rania IT 20000 Contract
103 Iyad IT 25000 Regular
104 Chaima HR 19000 Contract
e
Write a Python code to:
1. Create the DataFrame using Pandas
2. Calculate the average salary by employee status
3. Display the DataFrame in descending order of salary
4. Delete the column Status
5. Display the maximum salary in the IT department
6. Calculate the average salary by department and plot it as a bar chart:
○ Add a title
○ Add labels to both axes
Remarques importantes
● Indices commencent à 0
● Code clair = points assurés
● Imports obligatoires (pandas, matplotlib)
● Graphique avec titre et labels
✅ 100 % prêt pour Word / impression / distribution
Si tu veux, je peux aussi te fournir :
● le corrigé officiel Word
● un PDF
● une page de garde ENSA / OFPPT