# 12.9 Codecademy bug? Right answers printed, but still getting error message

#1

Hey everyone,

I'm doing Codecademy in French, but its the same--only the specific names are changed.
The last exercise of Student Becomes the Teacher requires the user to print the class average and the corresponding letter grade. I do this successfully, and my code works, but I keep on getting an error (that won't let me proceed) :

"Une des variables suivantes est manquante ou endommagée quand on essaye de l'utiliser : alice, lloyd, tyler, etudiants, calcule_classe_moyenne, ecrire_lettre_note"

This translates as "One of the following variables is missing or damaged when we try to use it: alice, llod, tyler, etudiants, calcule_classe_moyenne, ecrire_lettre_note"

My output on the Codecademy module is:
"83.8666666667
B
None"

Leading me to believe something is wrong. Thank you so much for you help!

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 = float(sum(nombres))

def calcule_moyenne(etudiant):
devoirs = moyenne(etudiant["devoirs"])
quiz = moyenne(etudiant["quiz"])
tests = moyenne(etudiant["tests"])
avg = .1*devoirs +.3*quiz + .6*tests
return avg

def ecrire_lettre_note(etudiants):
resultats = []
for etudiant in etudiants:
resultats.append(calcule_moyenne(etudiant))
if moyenne(resultats) >= 90:
return "A"
elif moyenne(resultats) >= 80:
return "B"
elif moyenne(resultats) >= 70:
return "C"
elif moyenne(resultats) >= 60:
return "D"
else:
return "F"

def calcule_classe_moyenne(students):
resultats = []
for etudiant in students:
resultats.append(calcul_moyenne(etudiant))
return moyenne(resultats)

etudiants = [lloyd, alice, tyler]

print calcule_classe_moyenne(etudiants)
print ecrire_lettre_note(etudiants)

#2

@jakobbrounstein,
You have written a ecrire_lettre_note() function
which expects a dictionary Value as an argument.

I think you will have to write a ecrire_lettre_note() function
which expects a number Value as an argument
like

def ecrire_lettre_note(resultat):
if resultat >= 90:
return "A"
elif resultat >= 80:
return "B"
elif resultat >= 70:
return "C"
elif resultat >= 60:
return "D"
else:
return "F"
#
# and then call the ecrire_lettre_note() function like
print ecrire_lettre_note(calcule_classe_moyenne([alice]))

### =========================================

def calcule_classe_moyenne(students):
resultats = []
for etudiant in students:
resultats.append(calcul_moyenne(etudiant))
return moyenne(resultats)

you will have to change resultats.append(calcul_moyenne(etudiant))
into resultats.append(calcule_moyenne(etudiant))