In: Computer Science
The whole is implemented in python |
f1=input("Enter the filename to read:- ") d1=input("Enter the filename to display:- ") l=[] p=[] with open(f1) as f: r=f.readlines() #preprocessing the file and storing in a list. for i in r: l.extend(i.split(" ")) for s in l: p.append(s.strip("\n")) l=[] for i in p: if(i!=''): l.append(int(i)) #total vals tval=len(l) #min mn=min(l) #max mx=max(l) #Average avg=sum(l)/tval #Standard deviatin std=0.0 for i in l: std=std+((i-avg)**2) std=std/tval std=std**0.5 #Displaying results print("Read from file: %d"%(tval)) print("Maximum Value: %d"%(mx)) print("Minimum Value: %d"%(mn)) print("Average Value: %.2f"%(avg)) print("Standard Deviation: %.2f"%(std)) #Writing to file d = open(d1, "w") d.write("Read from file:%d\n"%(tval)) d.write("Maximum Value: %d\n"%(mx)) d.write("Minimum Value: %d\n"%(mn)) d.write("Average Value: %.2f\n"%(avg)) d.write("Standard Deviation: %.2f\n"%(std)) d.close() |
Output Output in file... |