After finding the range, min, max and average from my text file of stored scores of my game, I would like to find the standard deviation from these scores but I am not sure how to go about it.
This is what I have so far:
file = open('stats.txt', 'a+')
file.write('\n' + 'Score: ' + str(1))
file.close()
numbers = []
with open('stats.txt') as fh:
count = 0
for line in fh:
count += 1
numbers.append(float(line.split()[1]))
file = open('maths.txt', 'w+')
file.write('Average Score: ' + str(sum(numbers)/len(numbers)) + "\n")
file.write('Maximum Score: ' + str(max(numbers)) + "\n")
file.write('Minimum Score: ' + str(min(numbers)) + "\n")
maxn = max(numbers)
minn = min(numbers)
rangex = (maxn) - (minn)
file.write('Range of Scores: ' + str(rangex))
file.close()
What my text file looks like:
Score: 3
Score: 0
Score: 13
Score: 13
Score: 9
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 31
Score: 0
Score: 0
Score: 0
Score: 0
Score: -8
Score: 0
Score: 0
Thanks for helping