I’m trying to figure out what’s wrong with my code. Could anyone fix it?
def main():
fname = input("Enter filename:")
infile = open(fname, "r")
SD()
def SD():
b= []
a = 5.0
r = len(b)
for n in range(r-1):
b.append((r[n] -a)**2)
m = (float(b)/r)**0.5
print("The standard deviation is", m)
main()
You have a handful of errors:
bis a list; you can’t cast a list into a float.perhaps you want to pass an array to
SD()? You shouldread()the files contents and then perhapssplit()that into an array and pass it to SD() as an argument (where you’ll callint()on them.)