Variance calculation not accurate


#1

I wrote the below to calculate variance but the hint tells the result is not accurate
#################################################
image


#2

There are several problems with your code.

to get the variance for all grades, we need to get the variance of each grade and add it together. That is why we have a loop. you nicely defined a variable (variance) to get the total variance.

Not sure why you also added tot, bit double to have two variables doing the same thing. Besides, if you want to add values to increase a variable, the variable should be defined outside the loop, otherwise its gets re-assigned zero each iteration of the loop

then after you loop, you calculate the variance in a variable called var. Which is good, but this should be outside/after the loop.

finally, the function call needs to be outside/after the function. Nesting is determined by indent


#3

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