Exam statistics python


What is the difference btn my code and the solution and what is the reason mine is wrong?

my code:

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

the solution:

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

By default, a function returns None at the end of the function. If we want to return something else at the end of the function, we can use the return keyword.

Given return is the last thing a function does, when a return keyword is reached, the function ends

so your function ends here:

return variance 

it never gets to the calculation of dividing total variance by the number of scores

1 Like