Its okay to be average


#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(total)
    len(total) / len(numbers)

i dont whats wrong
error:
Oops, try again. average([3, 0]) resulted in an error: object of type 'float' has no len()


#2

So this is what you have to do:

-make the sum inside the float function
-make a new variable called result
-make result's value to total divided by using the float function to convert the length of numbers.
-After that just return!

Sorry if I seem confusing but here is how it should end up:

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

#3

def promedio(numeros):
total = sum(numeros)
promedio = float(total) / len(numeros)
return promedio


#4

Hi there, nice solution candycornlover1. However, from going over the CC learning path we haven't been taught the nested parens solution you have above.

I'm trying to do via the tools suggested in the course so far, but am getting an error.

Here is my code:

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

My error code is: Oops, try again. average([3, 0]) resulted in an error: 'list' object has no attribute 'sum'


#5

I think there needs to be something in the parentheses of sum() and len()


#6

thanks guys i solved from so long now but i forgot to tell you


#7

It is okay! Just close this post so you don't get any more notifications!


#8

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