It's okay to be average

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/python-beginner-en-qzsCL/1/1?curriculum_id=4f89dab3d788890003000096#
<In what way does your code behave incorrectly? Include ALL error messages.>
I’m not getting an error code from the window, but instead Codecademy is saying “Oops, try again. Make sure you converted the total or the length to a float before the division - average([3, 0]) returned 1.0 instead of 1.5 as expected.”
As far as I can tell I did convert the total to a float before the division, so I don’t understand why I’m having this issue. Is there something wrong in my code (below)?
<What do you expect to happen instead?>

```python

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

Here are the instructions:

Write a function average that takes a list of numbers and returns the average.

Define a function called average that has one argument, numbers.
Inside that function, call the built-in sum() function with the numbers list as a parameter. Store the result in a variable called total.
Like the example above, use float() to convert total and store the result in total.
Divide total by the length of the numbers list. Use the built-in len() function to calculate that.
Return that result.

<do not remove the three backticks above>

On this line instead of using the modulo operator % use the division one /

hello @bandit

I have the same problem, i keep getting the error message “Oops, try again. Make sure you converted the total or the length to a float before the division - average([3, 0]) returned 1.0 instead of 1.5 as expected. …and ive tried the same code with the " /” instead of “%”

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

Same as for him, type this instead

result = total / len(numbers)

Notice I changed the %

1 Like

Got it ! @bandit Thankyou

1 Like

Simply this. Worked for me.

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

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

this gives an error. What worked for me was similar, but without the = between return and result:

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

I have also struggled with this one. You can use any of those (just try to understand what it all means ;):

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

or, like kind people before me said:

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