I am attempting to find the standard deviation of numbers in python. This is an entry level programming class so i am avoiding trying to use a function since they have not been introduced yet.
This program allows me to add numbers to a list, analyze said list, and then bring out the average, min, max, STDev, ect. I have managed to successfully display everything except STDev, the error i keep getting is float object not iterable. here is the code for the related part:
elif (menuchoice == 4):
sum = 0.0
print("std deviation")
stdev = 0.0
for i in range(listcount):
scorenum4 = eval(scorenum[i])
scoreaverage2 += scorenum4
scoreaverage2 /= listcount
for i in range(listcount):
stdev = []
scorenum3 = eval(scorenum[i])
stdev += (scorenum3 - scoreaverage2)**2
dev = sqrt((stdev)/listcount-1)
print(dev)
any help would be geat, thank you.
-Self edit - I just removed stdev=[] out of my for loop, not sure why it was there - I am getting an answer now, but it is mathematically off
- Changed to dev = sqrt((stdev)/listcount) and it fixed my math error, DSM confirmed this fix as well. Thank you
- Program is functioning properly now! woot. Thank you everyone for the advise.