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'}
]

def ajouter_etudiant(nom, prenom, promo):
    etudiant = {
        "nom": nom,
        "prenom": prenom,
        "notes": [],
        "coefficient": [],
        "promo": promo,
    }
    etudiants.append(etudiant)
    print(f"Étudiant {prenom} {nom} ajouté avec succès!")

def ajouter_note(etudiant_nom, note, coef):
    for etudiant in 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}")
            return
    print(f"Étudiant {etudiant_nom} non trouvé.")

def afficher_etudiants():
    if not etudiants:
        print("Aucun étudiant ajouté.")
        return
    for etudiant in etudiants:
        print(f"Nom: {etudiant['nom']}, Prénom: {etudiant['prenom']}, Promo: {etudiant['promo']}, Notes: {etudiant['notes']}, Coefficients: {etudiant['coefficient']}")

def afficher_etudiants_par_promo():
    promo = input("Vous voulez afficher quelle promo ? (1ère année ou 2ème année) ")
    etudiants_promo = [etudiant for etudiant in 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 compter_notes():
    etudiant_nom = input("Vous voulez savoir le nombre de notes de qui ? (Donner uniquement le nom de famille) ")
    for etudiant in etudiants:
        if etudiant['nom'] == etudiant_nom:
            nombre_de_notes = len(etudiant['notes'])
            print(f"L'étudiant {etudiant_nom} a {nombre_de_notes} note(s).")
            return nombre_de_notes
    print(f"Étudiant {etudiant_nom} non trouvé.")

def moyenne_etudiant():
    etudiant_nom = input("Vous voulez calculer la moyenne de quel étudiant ? (Donner que le nom de famille) ")
    for etudiant in 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}")

def compter_etudiants_par_promo():
    promo = input("Vous voulez compter le nombre d'étudiant de quelle promo ? (1ère année ou 2ème année) ")
    etudiants_promo = [etudiant for etudiant in etudiants if etudiant['promo'] == promo]
    nombre_etudiants = len(etudiants_promo)
    print(f"Il y a {nombre_etudiants} étudiant(s) en {promo}.")

def moyenne_promotion():
    promo = input("Vous voulez calculer la moyenne de quelle promo ? (1ère année ou 2ème année) ")
    etudiants_promo = [etudiant for etudiant in 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}.")

moyenne_promotion()