# It's Okay to be Average

#1

I'm trying to pull up the average, however it's failing though my code looks OK can anyone correct me in case something's wrong

it gives the following error:
Oops, try again.
average([3, 0]) returned 3.0 instead of 1.5 as expected.

``````I'm running the code below.

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

Error:

Oops, try again.
average([3, 0]) returned 3.0 instead of 1.5 as expected.``````

#2

alright it has worked npow

thnaks all

#3

Im having the same issue, what did you do to fix it?.

#4

If you have the same code as @deathscion, then this:

is your problem. You need to set the variable of total equal to that value like this:

`total = total/len(number)`
If that isn't your problem then post your entire code in a post to me. Hope that helps!

#5

I had the same error message as deathscion (it said: average([3, 0]) returned 3.0 instead of 1.5 as expected), even though I'd correctly written total = total/len(numbers). Then I realised that I'd written "print total" at the end instead of "return total". Here is my amended code - does this help you?

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

#6

Hi Forgxtten

I just applied total = total/len(numbers)

and that worked

#7

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