Oops, try again. get_class_average([alice]) returned 83.8666666667 instead of 91.15 as expected


#1

I am sure this code is correct, but still it throws an error. Could anyone tell me if they have come across this error earlier. I have posted the 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)
total /= len(numbers)
return total

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

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

get_letter_grade(get_average(lloyd))
student_list = [lloyd,alice,tyler]

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


#2

The indentations are corrent, FYI


#3

I have exactly the same problem and cant see why either...


#4

Hey All,

if you want to format your code when you paste it here you have three options

  1. select the code (after you paste it here) and press ctrl + k or
  2. select the code(after you paste it here) and press </> in the tools pane
  3. put this character ` three times at the begining and end of code

#5
def get_class_average(student_list):
results = []
for student in student_list:
results.append(get_average(student))
return average(results)

despite the above instruction I still couldn't figure out how to show the correct indentation but it seems you have that figured out.


#6

The final reply does not work out too. I have tried out everything possible. I think there is some problem with the run-time interface that codecedemy provides. Could anyone please check?


#7

Hey, I solved it...
The name of the list and the argument to pass to get_class_average should be the same, though I do not know why it is making a difference. It actually should not make a difference.


#8

that got it for me too, thanks!


#9

well I did that and still getting an error and I'm 100% positive that my code is just fine. I've even tried a code from some youtube guy who got it right on video still throws me an error. I'm really frustrated please help :frowning:


#11

My code works:

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):
    return float(sum(numbers)) / len(numbers)

def get_average(student):
    homework = 0.1 * average(student["homework"])
    quizzes = 0.3 * average(student["quizzes"])
    tests = 0.6 * average(student["tests"])
    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 student in students:
        result = get_average(student)
        results.append(result)
    return average(results)

#12

you just helped me a lot with your solution!
I was stuck with the same problem!

look at my code:

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_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 student in students:
results.append(get_average(student))
return average (results)

indent preformatted text by 4 spaces


#13

please update your code according to this manual:


#14

Thanks for your comment. But I'm surprised that the List Name should be same as Argument. Not sure why it has to be same. In my understanding, Argument is like any other variable and container. So it should take whatever we pass into it. Any explanation on this?