Error with alice/lloyd/tyler/students/get_class_average/get_letter_grade?


#1

I wrote most of the program and I'm getting an error message saying that alice/lloyd/tyler/students/get_class_average/get_letter_grade is either broken or missing but I can't seem to find what's wrong with the code.

I'm stuck on this exercise in the How is Everybody Doing exercise.

The output I get when I run the code is 83.867 for the class average and B for the letter grade, so I'm assuming the code is working properly but I get an error message and I'm really confused with why.

code below:

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)/len(numbers)
    return total
    
def get_average(student):
    homework = average(student['homework'])*0.10
    quizzes = average(student['quizzes'])*0.30
    tests = average(student['tests'])*0.60
    return homework + quizzes + tests
    
def get_letter_grade(score):
    if score >= 90:
        return 'A'
    elif score >= 80:
        return'B'
    elif score >= 70:
        return 'C'
    elif score >= 60:
        return 'D'
    else:
        return 'F'

def get_class_average(students):
    results = []
    for item in students:
        avg = get_average(item)
        results.append(avg)
    return average(results)
    
c_avg = get_class_average([lloyd, alice, tyler])
print c_avg
c_lg = get_letter_grade(c_avg)
print c_lg

#2

Hi,

can you post your code using the Preformatted text button? Otherwise we can't see the formatting of you code.


#3

the students list you build in this exercise is missing, you need this list in order to pass (the exercise tells you its missing)


Error in "How is Everybody Doing?" exercise
#4

Hi,
I get the same error and stuck here.
Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected
and no clue what’s wrong.


#5

Hi!

I had the same problem, and the only problem was that I was missing the students list ( students = [lloyd, alice, tyler] )

But I still don’t know why this list was causing an error as the output did not rely on the value/existence of this list (students). Also, I double checked and saw that I was missing the students list line after that exercise and the code was working completely fine.

Since this assignment was in the last lesson of that section, I’m assuming that Codecademy just requires this list in the final version of the code since they want us to have the “full” code and each assignment in that lesson but is there any other explanations?


#6

@manishchristie, clearly you have a different problem, but its impossible to say what it is given you didn’t include any details at all which could help us indentify the problem. Make a new topic, fill in the template so we have all the details needed to help you. Hijacking topics is a violation of the guidelines

i would argue that having the list of students would be a good design for your program, along with indeed the fact codecademy verifies all the important components of your program are present


#7

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