#Program to read numbers from a file and determine histogram of the data:
f1=open("hg3.d","r")
n=input("Enter the no. of lines:")
n=int(n)
h=[0 for i in range (n)]
x=[]
for i in f1:
x.append(eval(i))
t=len(x)
mn=min(x)
mx=max(x)
R=(mx-mn)*1.01
bs=R/n
for i in range (t):
k=int(abs((h[i]-mn)/bs))
h[k]=h[k]+1.0
f=[]
for i in range (n):
d=mn+(i*bs)
f.append(d)
f1.close()
f2=open("hg2.d","w")
a=len(f)
for i in range (a):
print(h[i],f[i],"-",f[i]+bs,file=f2)
f2.close
f1=open("hg3.d","r")
n=input("Enter the no. of lines:")
n=int(n)
h=[0 for i in range (n)]
x=[]
for i in f1:
x.append(eval(i))
t=len(x)
mn=min(x)
mx=max(x)
R=(mx-mn)*1.01
bs=R/n
for i in range (t):
k=int(abs((h[i]-mn)/bs))
h[k]=h[k]+1.0
f=[]
for i in range (n):
d=mn+(i*bs)
f.append(d)
f1.close()
f2=open("hg2.d","w")
a=len(f)
for i in range (a):
print(h[i],f[i],"-",f[i]+bs,file=f2)
f2.close
Comments
Post a Comment