I am trying to create a function that prints the variance of a list of specific numbers:
grades = [100, 100, 90, 40, 80, 100, 85, 70, 90, 65, 90, 85, 50.5]
So far, I have tried to continue these three functions:
def grades_sum(my_list): total = 0 for grade in my_list: total += grade return total def grades_average(my_list): sum_of_grades = grades_sum(my_list) average = sum_of_grades / len(my_list) return average def grades_variance(my_list, average): variance = 0 for i in my_list: variance += (average - my_list[i]) ** 2 return variance / len(my_list)
However, when I try to execute the code, it causes the following error in the following line:
Line: variance += (average - my_list[i]) ** 2 Error: list index out of range
Sorry if my current knowledge of Python is limited, but I'm still involved - so please, if you want to help solve this problem, try not to offer extremely complex ways to solve this problem, thank you very much.
source share