Standard Deviation


#1

def grades_variance(scores):
average = float(grades_average(scores))
variance = 0
for score in scores:
x = float((average - score) ** 2)
variance += x
result = float(variance) / float(len(scores))
return result

print grades_variance(grades)

def grades_std_deviation(variance):
x = grades_variance(variance)
result = float(x) ** 0.5
return result

print grades_std_deviation(grades)

the error says 'float' object is not iterable

  1. WHY WON'T THIS WORK?
  2. WHY DO I HAVE TO x = grades_variance(variance) outside the function?


Replace this line with your code.


#2

All you are required to is raise the variance by 0.5 and return it,

return variance ** 0.5

you don't need a variable for that. :slight_smile:

But remember on a new indentation level you need to set a variable equal the function grades_variance with the argument (grades),

example_var = grades_variance(grades)


#3

I agree I am a little too succinct to use a variable for returning the result!

Re: Edited questions
1. What does this error float object not iterable mean? for ex in this case
2. Why can't I store the variance in a variable that is inside the function? and obtain the deviation by simply calling the grades..


#4

float and int objects are not iterable.

Well you can store a function call to another function inside a different function. The question is, why would you like to do that?


#5

"Well you can store a function call to another function inside a different function." >> I don't understand this. Can someone with better communication skills break it down to me please?

Because then I get to call the function using just the print command, and when I call the function anytime again, I don't have to add the value of variance to it. Just the print, call. So?


#6

What I mean by this,

is for example,

def add(x,y):
	return x + y

def return_add():
	return add(2,4)

I have called the add function inside the return_add function.


#7

isn't grade average already a float? (your line 2: average = float(grades_average(scores))).


#8

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