6/9 Can't get the weighted average to come out right


#1

So I've looked at other topics to help, and I've even copied and pasted code to see if I'm just messing up syntax or something. But when I click 'save and submit code' an error pops up and I don't understand it at all. Help would be much appreciated!!!


#2

Here is my codebit for you to study. From what I can see you are doing the math correctly but who knows with the judge on here.

MY CODE:

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

#3

I tried it and it still came up with that error, I sort of think it has to do with the first average part or the original numbers even though they were given to us... I don't know, this is weird. But thank you for your help :smile:


#4

Below is the whole code I have that passes, compare it to yours.

It's for 9/9 btw.

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):
    return sum(numbers) // len(numbers)
    
def get_average(student):
    return (0.1 * average(student["homework"]) + 0.3 * average(student["quizzes"]) + 0.6     * average(student["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"

students = [lloyd, tyler, alice]

def get_class_average(students):
    return average([get_average(student) for student in students])
    
print get_class_average(students)
print get_letter_grade(get_class_average(students))

#5

It's cheating, I know... I copied your code just to see if it would work for me since it worked for you. And it returned 91 instead of 91.5. I just switched out your def average(numbers) bit of code for mine and it worked wonderfully!! Thank you so much for your help!!


#6

This is how wrote the code. Just in case anyone wants to look it over.
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


#7

I've shortened the code.

def get_average(student):
return .1 * average(student["homework"]) + .3 * average(student["quizzes"]) + .6 * average(student["tests"])


#8


#9

this one is batter