Aller au contenu

Correction de l'épreuve 40

Sujet (PDF intégré)

Exercice 1

def recherche_indices_classement(elt, tab):
    ind_inf = []
    ind_egal = []
    ind_sup = [] 
    for i in range(len(tab)):
        if tab[i] < elt:
            ind_inf.append(i)
        elif tab[i] > elt:
            ind_sup.append(i)
        else:
            ind_egal.append(i)
    return (ind_inf, ind_egal, ind_sup)
Ou

def moyenne(resultats, eleve):
    if eleve not in resultats:
        return None

    total = 0
    coeffs = 0
    for epreuve in resultats[eleve]:
        note, coeff = resultats[eleve][epreuve]
        total += note * coeff
        coeffs += coeff

    if coeffs == 0:
        return 0

    return total / coeffs

Exercice 2

def moyenne(nom, resultats):
    '''Renvoie la moyenne de l'élève nom, selon le dictionnaire 
    resultats. Si nom n'est pas dans le dictionnaire, 
    la fonction renvoie None.'''
    if nom in resultats: 
        notes = resultats[nom]
        if notes == {}: # pas de notes 
            return 0
        total_points = 0 
        total_coefficients = 0 
        for valeurs in notes.values(): 
            note, coefficient = valeurs
            total_points = total_points + note * coefficient 
            total_coefficients = total_coefficients + coefficient 
        return round( total_points / total_coefficients, 1 ) 
    else:
        return None

Commentaires éventuels

Bon, enfin un truc un peu mieux, même SI ENCORE DES MOYEEEEEEEEEEENNES RAAAAAAAAAAAH

Précédent | Suivant