Hi, I'm in first year computer science and could use some help on a program where I have to calculate the standard deviation from data on a txt file. Using some online help I've gotten somewhere but to be honest don't really know what's going on myself.
The program is meant to use data from an outside file so I can't hard code numbers or have the user input data.
data = open("datafile1.txt")
print data.read()
~stuff in between~
# a = numbers
# r = number of values in data
# m = mean (already calculated earlier in the programming)
def SD():
....b = []
....for n in range(r-1):
...........if r[n] > a:
.................b.append((r[n] - a)**2)
...........if r[n] < m:
.................b.append((a - r[n])**2)
...........SD = (float(b)/r)**0.5 #float because the data includes decimal values
....return SD
print "The standard deviation is", SD
Unfortunatly this is the result I get, including the number of values and mean which I had to calculate as well:
There are 4 records
The mean is 3.1422
The standard deviation is <function SD at 0x020EB630>
The standard deviation is <function SD at 0x058F6F30>
The standard deviation is <function SD at 0x020EB630>
The standard deviation is <function SD at 0x0552BA70>
The standard deviation is <function SD at 0x020EB630>
Could someone help me this?