# 9/9 How is Everybody Doing? Correct answer but error?

#1

https://www.codecademy.com/courses/learn-python/lessons/student-becomes-the-teacher/exercises/how-is-everybody-doing-?action=lesson_resume

Error message: One of the following is missing or broken when we tried to use it: alice, lloyd, tyler, students, get_class_average, get_letter_grade

I expected it to work because I received answers in the Console (although I did not manually check to see if they’re accurate):
83.8666666667
B

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

def average(numbers):
total = sum(numbers)
total = float(total)
return total/len(numbers)

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

def get_class_average(class_list):
results = []
for student in class_list:
student_avg = get_average(student)
results.append(student_avg)
return average(results)

class_list = [lloyd, alice, tyler]
class_average = get_class_average(class_list)
print class_average

def get_letter_grade(class_list):
for student in class_list:
if class_average >= 90:
return "A"
elif class_average >= 80:
return "B"
elif class_average >= 70:
return "C"
elif class_average >= 60:
return "D"
else:
return F

print get_letter_grade(class_list)

``````

#2
``````def get_letter_grade(class_list):
for student in class_list:
if class_average >= 90:
return "A"
elif class_average >= 80:
return "B"
elif class_average >= 70:
return "C"
elif class_average >= 60:
return "D"
else:
return F
``````

see anything wrong with this?

#3

I’m sorry I’m not really sure!

#4

What is the intended role of ‘get_letter_grade’? To take a grade (a number) and return a corresponding letter grade. It does not take a list, and it will certainly not be using the variable, ‘class_average’.

``````def get_letter_grade(grade):
if grade >= 90:
return "A"
elif grade >= 80:
return "B"
elif grade >= 70:
return "C"
elif grade >= 60:
return "D"
else:
return "F"
``````

#5

One of these `return` values is not like the others,
One of these `return` values just doesn’t belong,
Can you tell which `return` value is not like the others
By the time I finish my song?

#6

Ah! I forgot quotes!

#7

I had suspected that, but I’ve not done the python course so I wasn’t sure… But hey, that’s not the only issue with it.

#8

Ugh sorry please ignore my last comment that was instead of this one. I was a screen backwards instead. Still working through it. Will keep the thread posted…

#9

Did you see @mtf’s comment?

#10

Ok that’s really helpful. Does not take a list. Ok. I read some of the other comments on this particular exercise and saw a for loop was necessary so I was trying to build one that would work. I’m gonna try re-working it.

#11

Ok, please go easy, I’m still understanding basics here. Any clues anyone can offer or pointers of what I think I’m telling the code to do without realizing what I’m actually telling it to do, etc? Something’s getting lost in the attempt to find the letter grade of the class average.

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

# Add your function below!
def average(numbers):
total = sum(numbers)
total = float(total)
return total/len(numbers)

def get_average(student):
homework = average(student["homework"])
quizzes = average(student["quizzes"])
tests = average(student["tests"])
return 0.1 * homework + 0.3 * quizzes + 0.6 * tests

def get_class_average(class_list):
results = []
for student in class_list:
student_avg = get_average(student)
results.append(student_avg)
return average(results)

class_list = [lloyd, alice, tyler]
class_average = get_class_average(class_list)
print class_average

def get_letter_grade(class_average):
for grade in class_average:
if grade >= 90:
return "A"
elif grade >= 80:
return "B"
elif grade >= 70:
return "C"
elif grade >= 60:
return "D"
else:
return "F"

print get_letter_grade(class_average)
``````

#12

Go back to what the intended role of the function is… return a letter. There is no loop, no class_list and no class_average variable. Just `grade`.

``````print get_letter_grade(class_average)
``````

That is correct. Now just fix the function so it uses `grade`. The function is not just for class average grade letter, it is for any grade, student, average, class average, subject, etc. A single value is passed in, a single letter is passed out.

#13

What you need is two separate, working pieces:

1. `get_class_average`: This should take a list as input and return a number grade.
2. `get_letter_grade`: This should take a number grade as input and return a letter grade.

I bet you can figure out how to put that together

#14

These Q&A topics are specifically geared to the actual course material. Suggest you do the Python track so when you answer here it is always based on the actual lesson. Without knowing what is asked and expected it is easy to mislead learners.

#15

Ok great thanks so much!

It’s interesting how sometimes the code is effective yet not as ideal as it could be and still throws errors whereas if I put it into a Python Runner it comes up with the correct answer and doesn’t throw any errors. I think I somehow mixed up the way I had built up the code and the functions from previous lessons within code academy’s framework and that was confusing me. That happens sometimes when I start and stop in the middle of a group of lessons. It’s def a learning experience so thx for the help!

#17

A post was split to a new topic: Did you properly indent each element?

#18

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.