6. Just Weight and See


#1

Hi,

I can't validate this level, I've the good result at the end but with two line.
First line the result and second line : "None". Why ?

Thank you !!

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

def get_average(student):
    homework1 = average(student["homework"])*0.1
    homework2 = average(student["quizzes"])*0.3
    homework3 = average(student["tests"])*0.6
    avefinal = (homework1 + homework2 + homework3)
    print avefinal
get_average(alice)

#2

@cssslayer42572,

Use

return avefinal

print( get_average(alice) )

#3

Good hint! I forgot to call the "alice" function.
My code ended like this:

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

get_average(alice)


#4

Thanks for the answer, but what I'm confused about is how the code knows that alice, lloyd, and tyler are students. When you put in print get_average(lloyd) at the end, it will give you lloyd's average in the console, but how does it exactly know that lloyd is a student?


#5

@20dannyb,

The code doesn't know anything else, as that what you are defining/declaring.

If you use the argument lloyd you are pointing to
the variable lloyd with
its associated dictionary Value

{
    "name": "Lloyd",
    "homework": [90.0, 97.0, 75.0, 92.0],
    "quizzes": [88.0, 40.0, 94.0],
    "tests": [75.0, 90.0]
}