-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestPersonne.py
37 lines (30 loc) · 961 Bytes
/
TestPersonne.py
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
37
class Personne:
def __init__(self,nom,prenom):
self.nom=nom
self.prenom=prenom
def __str__(self):
return self.nom+" "+self.prenom
class Etudiant(Personne):
NB=0;
def __init__(self,nom,prenom,num):
super().__init__(nom,prenom)
self.num=num
Etudiant.NB+=1
def __str__(self):
return super().__str__()+" Student "+str(self.num)
if __name__ == '__main__':
# TEST 1 : Une instance
p = Personne("Duchemin","paul");
print(p)
# TEST 2 : Une collection
al1 = [Personne("Duchemin"+str(i),"paul"+str(i)) for i in range(1,11)]
for p in al1: print(p)
# TEST 3 : Polymorphisme
al2 =[]
for i in range(1,10):
if i%2==0:
al2.append(Personne("Duchemin"+str(i),"paul"+str(i)))
else:
al2.append(Etudiant("Durand"+str(i),"jules"+str(i) , i))
for p in al2: print(p)
print("Nb etudiants "+str(Etudiant.NB))