It's ok to be average


OK so I'm actually proud of myself as I got this far without help....Now I'm stuck and can't seem to find the answer.

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

This should return the correct value.. At least I believe that it should. I sum(numbers) > convert to float > divide and return. Not difficult but it's returning an error. I blame the Buffalo Trace but I really can't figure this one out.

Anyone help a fellow chap out?


Hahaha... nvm. I see what I did wrong. Please don't flame the living daylight out of me. =D


i have the same problem, then i change the code and put it this way:

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

and the problem was solved. hope it help


Okay, so I got the same coding but with = total at the end instead of total = at the front of each line. Can someone explain why that doesn't work. I think I have jumbled the logic in my head.


Well if you look at my code. Everything was correct except for what I was returning. Hope this helps Chaps!


i think my code has been simply written and it works:

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


this is my code:

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

print averege([1, 1, 1, 1, 1,])

much likes the other posts in here the console gets the right averege but the exersice wont go forwarwrd gives me a "Oops, try again. average seems to be missing." notification.


ive called the 'averege' function in the lower line just to check it and it worked fine. so you may ignore that line. even without it it gave me the same "eror".


You spelled average wrong. It isn't averege.


jesus that was stupid lol
thanks brother


i used this:

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

tried first with float(numbers.sum()) but wasn't sure if sum() function could be used like that.... indeed it can't :stuck_out_tongue:

P.S.: i did the bad spelling of "average" too eheh


You should return it to "average" instead of "total"


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

this worked for me


This is a syntax error. You should put total before the =, being:
total = sum(numbers)


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

and i'm having this message:
Oops, try again. average([3, 0]) returned None instead of 1.5 as expected.

Can someone tell me where i'm going wrong??


Hey all, thanks for the replies. This helped with my understanding how to apply the steps in the challenge.
I still have a long way to go...
My solution that works thanks to you all:

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



your code is wrong because you aren't returning anything, and you stating that average equals the total divided by the length of numbers by using '==' when instead you should be assigning the total/len (numbers) as value to average by using '=' and ending your code with return average


Hey presto! - Thank you very much twinstubz, it always helps when the solution is provided with the formatting.