Pour revenir en arrière :
R308 - Consolidation de la programmation
etudiants = [
{'nom': 'Lalanne', 'prenom': 'Titoan', 'notes': [14, 18], 'coefficient': [0.5, 2], 'promo': '1ère année'},
{'nom': 'Labachot', 'prenom': 'Thomas', 'notes': [15, 20], 'coefficient': [0.5, 2], 'promo': '2ème année'}
]
class Etudiant:
def __init__(self, etudiants):
self.etudiants = etudiants
def ajouter_note(self, etudiant_nom, note, coef):
for etudiant in self.etudiants:
if etudiant['nom'] == etudiant_nom:
etudiant['notes'].append(note)
etudiant['coefficient'].append(coef)
print(f"Note {note} ajoutée pour l'étudiant {etudiant_nom} avec un coefficient de {coef}")
print(f"Étudiant {etudiant_nom} non trouvé.")
def compter_notes(self, etudiant_nom):
for etudiant in self.etudiants:
if etudiant['nom'] == etudiant_nom:
nombre_de_notes = len(etudiant['notes'])
print(f"L'étudiant {etudiant_nom} a {nombre_de_notes} note(s).")
print(f"Étudiant {etudiant_nom} non trouvé.")
def moyenne_etudiant(self, etudiant_nom):
for etudiant in self.etudiants:
if etudiant['nom'] == etudiant_nom:
total_notes = 0
total_coefficients = 0
nombre_de_notes = len(etudiant['notes'])
for i in range(nombre_de_notes):
note = etudiant['notes'][i]
coef = etudiant['coefficient'][i]
total_notes += note * coef
total_coefficients += coef
moyenne = total_notes / total_coefficients if total_coefficients != 0 else 0
print(f"La moyenne de l'étudiant {etudiant['prenom']} {etudiant_nom} est de {moyenne:.2f}")
class Promotion:
def __init__(self, etudiants):
self.etudiants = etudiants
def ajouter_etudiant(self, nom, prenom, promo):
etudiant = {
"nom": nom,
"prenom": prenom,
"notes": [],
"coefficient": [],
"promo": promo,
}
self.etudiants.append(etudiant)
print(f"Étudiant {prenom} {nom} ajouté avec succès!")
def afficher_etudiants_par_promo(self, promo):
etudiants_promo = [etudiant for etudiant in self.etudiants if etudiant['promo'] == promo]
if not etudiants_promo:
print(f"Aucun étudiant trouvé pour la promotion {promo}.")
return
print(f"Étudiants en {promo}:")
for etudiant in etudiants_promo:
print(f"Nom: {etudiant['nom']}, Prénom: {etudiant['prenom']}, Notes: {etudiant['notes']}, Coefficients: {etudiant['coefficient']}")
def moyenne_promotion(self, promo):
etudiants_promo = [etudiant for etudiant in self.etudiants if etudiant['promo'] == promo]
if not etudiants_promo:
print(f"Aucun étudiant trouvé pour la promotion {promo}.")
return
total_moyenne_promo = 0
nombre_etudiants_avec_notes = 0
for etudiant in etudiants_promo:
if etudiant['notes']:
total_notes_ponderees = 0
total_coefficients = 0
for note, coef in zip(etudiant['notes'], etudiant['coefficient']):
total_notes_ponderees += note * coef
total_coefficients += coef
moyenne_etudiant = total_notes_ponderees / total_coefficients
total_moyenne_promo += moyenne_etudiant
nombre_etudiants_avec_notes += 1
if nombre_etudiants_avec_notes == 0:
print(f"Aucun étudiant avec des notes dans la promotion {promo}.")
return
moyenne_generale_promo = total_moyenne_promo / nombre_etudiants_avec_notes
print(f"La moyenne générale de la promotion {promo} est de {moyenne_generale_promo:.2f}.")
etudiants_instance = Etudiant(etudiants)
promo_instance = Promotion(etudiants)
#etudiants_instance.ajouter_note("Labachot", 10, 1.5)
#etudiants_instance.compter_notes("Labachot")
#etudiants_instance.moyenne_etudiant("Labachot")
promo_instance.ajouter_etudiant("Laffite", "Tommy", "1ère année")
#promo_instance.afficher_etudiants_par_promo("1ère année")
etudiants_instance.ajouter_note("Laffite", 10, 1.5)
promo_instance.moyenne_promotion("1ère année")