Source de etudiant2.py
1: ### implémentation du type abstrait Étudiant
2: ### avec des listes Python
3:
4: def créer_étudiant(n,p,a):
5: return { 'prenom':p , 'nom':n , 'année':a ,
6: 'math':-1 , 'info':-1 ,
7: 'moyenne':-1 }
8:
9: def nom_étudiant(e):
10: return e['nom']
11:
12: def prénom_étudiant(e):
13: return e['prenom']
14:
15: def naissance_étudiant(e):
16: return e['année']
17:
18: def notemath_étudiant(e):
19: return e['math']
20:
21: def noteinfo_étudiant(e):
22: return e['info']
23:
24: def notediscipline_étudiant(d,e):
25: return e[d]
26:
27: def moyenne_étudiant(e):
28: return e['moyenne']
29:
30: def modifier_notemath(e,n):
31: e['math'] = n
32:
33: def modifier_noteinfo(e,n):
34: e['info'] = n
35:
36: def calculer_moyenne_étudiant (e):
37: e['moyenne'] = (e['math'] + e['info']) /2
38:
39: def afficher_etudiant(e):
40: print()
41: print("-----------------------------------")
42: print("| Prénom :",e['prenom'])
43: print("| Nom :",e['nom'])
44: print("| Naissance en :",e['année'])
45: print("| Note mathématiques : ",end="")
46: if e['info']>=0:
47: print(e['info'])
48: else:
49: print('-')
50: print("| Note informatique : ",end="")
51: if e['math']>=0:
52: print(e['math'])
53: else:
54: print('-')
55: print("| Moyenne : ",end="")
56: if e['moyenne']>=0:
57: print(e['moyenne'])
58: else:
59: print('-')
60: print("-----------------------------------")
61: print()
62:
63: ### tests
64:
65: moi = créer_étudiant('Faine','Robert',2000)
66: afficher_etudiant(moi)
67: modifier_noteinfo(moi,16)
68: modifier_notemath(moi,14)
69: afficher_etudiant(moi)
70:
71: jsp = créer_étudiant('sans Peur','Jean',1371)
72: modifier_noteinfo(jsp,12)
73: modifier_notemath(jsp,11)
74: calculer_moyenne_étudiant(jsp)
75: afficher_etudiant(jsp)
76:
77: jb = créer_étudiant('Bonsergent','Jacques',1912)
78: modifier_noteinfo(jb,14.0)
79: modifier_notemath(jb,8)
80: calculer_moyenne_étudiant(jb)
81: afficher_etudiant(jb)
82:
83: at = créer_étudiant('Turing','Alan',1912)
84: modifier_noteinfo(at,20)
85: modifier_notemath(at,10.5)
86: calculer_moyenne_étudiant(at)
87: afficher_etudiant(at)
88:
89: kg = créer_étudiant('Gödel','Kurt',1906)
90: modifier_noteinfo(kg,13)
91: modifier_notemath(kg,17.5)
92: calculer_moyenne_étudiant(kg)
93: afficher_etudiant(kg)