Send a letter


#1

bonsoir, I don't find my error;
please, help me and sorry for my english...

lloyd = {
"noms": "Lloyd",
"devoirs": [90.0, 97.0, 75.0, 92.0],
"quiz": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"noms": "Alice",
"devoirs": [100.0, 92.0, 98.0, 100.0],
"quiz": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"noms": "Tyler",
"devoirs": [0.0, 87.0, 75.0, 22.0],
"quiz": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}

Ajoutez votre fonction ci-dessous !

def moyenne(nombres):
total = sum(nombres)
total = float(total)
resultat= total/len(nombres)
return resultat

def calcule_moyenne(etudiant):
devoirs = moyenne(etudiant["devoirs"])
quiz = moyenne(etudiant["quiz"])
tests = moyenne(etudiant["tests"])
moyenne = 0.1*devoirs+0.3*quiz+0.6*tests
return moyenne

def ecrire_lettre_note(note):
if note >= 90.0:
return "A"
elif note >= 80.0:
return "B"
elif note >= 70.0:
return "c"
elif note >=60.0:
return "D"
else:
return "F"

print ecrire_lettre_note(calcule_moyenne(lloyd))
Traceback (most recent call last):
File "python", line 47, in
File "python", line 28, in calcule_moyenne
UnboundLocalError: local variable 'moyenne' referenced before assignment


#2

@textsolver97036,

lloyd = {
 "noms": "Lloyd",
 "devoirs": [90.0, 97.0, 75.0, 92.0],
 "quiz": [88.0, 40.0, 94.0],
 "tests": [75.0, 90.0]
}
alice = {
 "noms": "Alice",
 "devoirs": [100.0, 92.0, 98.0, 100.0],
 "quiz": [82.0, 83.0, 91.0],
 "tests": [89.0, 97.0]
}
tyler = {
 "noms": "Tyler",
 "devoirs": [0.0, 87.0, 75.0, 22.0],
 "quiz": [0.0, 75.0, 78.0],
 "tests": [100.0, 100.0]
}

#Ajoutez votre fonction ci-dessous !

def moyenne(nombres):
 total = sum(nombres)
 total = float(total)
 resultat= total/len(nombres)
 return resultat

def calcule_moyenne(etudiant):
    devoirs = moyenne(etudiant["devoirs"])
    quiz = moyenne(etudiant["quiz"])
    tests = moyenne(etudiant["tests"])
    moyenne1 = 0.1*devoirs+0.3*quiz+0.6*tests
    return moyenne1

def ecrire_lettre_note(note):
 if note >= 90.0:
   return "A"
 elif note >= 80.0:
   return "B"
 elif note >= 70.0:
   return "c"
 elif note >=60.0:
   return "D"
 else:
   return "F"

print ecrire_lettre_note(calcule_moyenne(lloyd))