5/9 python


#1

it passed. code is right but how to i get some output in a terminal
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):
total = sum(numbers)
print total
total = float(total)
total = total / len(numbers)
return total

......do i print average(numbers) or what to I do to get the code to print output in terminal?


#2

Printing intermediate results is okay for debugging, but otherwise in cases where a function is doing math, it might be best to just let it do the math, and output the return value, outside of the function.

def average(numbers):
    return float(sum(numbers)) / len(numbers)

print average(tyler['homework'])     # 46.0

It's important to note that numbers in the parameter is a list object.