It's ok to be average


#1

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?


#2

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


#3

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


#4

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.


#5

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


#6

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


#7

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.
why?


#8

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".


#9

You spelled average wrong. It isn't averege.


#10

jesus that was stupid lol
thanks brother


#12

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


#13

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


#14

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

this worked for me


#15

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


#16

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

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??


#17

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)

cheers!


#18

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


#19

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


#20