5/9 help me


#1

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(numbers)
total % len(numbers)
return total


#2

Here you go I have comment this code. Try an see if you can understand it and play arround with it

def average(numbers):
    #first total is 0
    total = 0
    #loop through numbers
    for i in numbers:
        #add each value to the total
        total += i
    #convert total to float and return it
    return float(total)/len(numbers)

#3

In the instructions it says to use the Sum() function. Why Didn't you use it? is it easier to just use the += operator?


#4

@james1468 yes you can also use the sum function like below. As to which method to use it depend on the programmer. Although I guess the sum function gives you much less code to write

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

the change you need to make in yours is to change the % to /