It's Okay to be Average


#1

Hi, I’m stuck on the exercise “It’s Okay to be average”, could some one help me please?

The instructions:
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.

Error message I get:
average([3, 0]) returned 3.0 instead of 1.5 as expected.

My code:


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



#2

the division you do here:

total / len(numbers)

isn’t stored anywhere, so you have to return it, or store it in a variable so you can return it later


#3

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