Just Weight and See


#1

I'm not too sure where I'm going wrong here..

I keep getting the error "Oops, try again. get_average(alice) returned None instead of the expected 91.15"

alice is present and defined so I dont understand why it is pulling none instead of 91.15...

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


#2

Once we assign the return value of a function call to a variable, we can/should use that variable.

Also, the return keyword is missing.

Consider,

homework = average(student["homework"])    # no comma here
# ...

return 0.1 * homework + \
# ...

#3

thank you I got it

for educational purposes. I don't understand why

average(student["homework"]) != homework when I put it in that syntax for my code earlier when homework the variable is defined as such.


#4

Not sure I follow. Rephrase the question, please. Thanks.


#5

Initially I had my code as:

0.1 * average(student["homework"])

is that not the same thing as

0.1 * homework


#6

If homework is defined as that, yes. Your solution defined the variables, but then didn't make use of them. All three of those first lines can be deleted so long as the next line starts with return. Else, define all three as you have, and use them as demonstrated earlier.

There a few ways we could come up with to fulfill this task, The current approach of using variables can be refined, using your code,

as in,

homework = 0.1 * average(student["homework"])

Then there will be less math in the return, simple addition. I've seen people using the sum() function, but's not expected in the solution. Simple .. + .. + .. will suffice for the exercise.


#7

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