Just weight and See: I am quite confused


#1



I get : "Oops, try again. get_average(alice) raised the following error: sum expected at most 2 arguments, got 3" as error message.


I don't understand where and how I got it wrong. Please help me


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(number):
    total = sum(number)
    total = float(total)
    return total/len(number)
    
def get_average(student):
    homework = average(student["homework"])
    quizzes = average(student["quizzes"])
    tests = average(student["tests"])
    
    homework = 0.1*average(student["homework"]) 
    quizzes = 0.3*average(student["quizzes"])
    tests = 0.6*average(student["tests"])
    
    grade = sum(homework, quizzes, tests)
    
    return grade


#2

sum() is a built in function to get the sum of iterable (like a list), to add numbers/variable containing numbers together simple use plus (+) operator


#3

Thanks a lot.... Resolved


#4

In what case do we use sum()?


#7

covered usage for sum() already in my answer?


#8

def get_average(student):
homework =average(student["homework"])*.10
quizzes = average(student["quizzes"])*.30
tests= average(students["tests"])*.60
return sum(homework+ quizzes+ tests)

anyone know why this isn't working?


#9

I mean this...

def get_average(student):
homework =average(student["homework"])*.10
quizzes = average(student["quizzes"])*.30
tests= average(students["tests"])*.60
return homework+ quizzes+ tests

it said global name 'students' is not defined


#10

now it says get_average(alice) raised the following error- list indices must be int not string

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!

student = [lloyd, alice, tyler]

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

def get_average(student):
homework =average(student["homework"])*.10
quizzes = average(student["quizzes"])*.30
tests= average(students["tests"])*.60
return homework + quizzes + tests


#11

make sure you write down the argument EXACTLY the same. There's an error in your "tests" line..


#12

here:

tests= average(students["tests"])*.60

you calculate the average test grade of students, but this should be the average test grade for a single student.