Mar-24-2022, 11:48 PM
Hello everyone
This goal of this assignment is to use a separate text file and then use the numbers within it and compute the variance. My professor has barred us from using the variance library function, so we have to do it manually. I believe I'm close I just can't figure out why I'm getting a ZeroDivisionError.
This is what I have so far:
2
3
4
-1
3
Any help is greatly appreciated thanks for looking.
This goal of this assignment is to use a separate text file and then use the numbers within it and compute the variance. My professor has barred us from using the variance library function, so we have to do it manually. I believe I'm close I just can't figure out why I'm getting a ZeroDivisionError.
This is what I have so far:
l = [] with open('in3.txt') as f: for line in f: numstr = line.rstrip().lstrip() numstr = int(numstr) l.append(numstr) total = 0 for i in l: total = i + total mean = total / len(l) total2 = 0 total3 = 0 for i in l: total2 = (i - mean) ** 2 total3 = total2 + total3 total3 = total3 / (len(l) - 1) print(total3)the text file is called 'in3' and it reads:
2
3
4
-1
3
Any help is greatly appreciated thanks for looking.