# Program to read number from file containing some repetition.Find the frequency distribution and # hence the mode of the distribution.write the frequency distribution in a different file.
f1=open("fd.d","w")
n=input("Enter the no. of dimention:")
n=int(n)
x=[]
for i in range (n):
s=input("Enter the value:")
s=float(s)
x.append(s)
for i in range (n):
for j in range (i+1,n):
if x[i]>x[j]:
a=x.pop(j)
x.insert(i,a)
print("The list of numbers in ascending series=",x,file=f1)
f1.close()
f1=open("fd.d","r")
V=[x[0]]
F=[]
f=1
for i in range (1,n):
if x[i]==V[-1]:
f=f+1
else:
F.append(f)
f=1
V.append(x[i])
F.append(f)
s=len(V)
e=[]
for i in range(1,s-1):
if F[i]>F[i-1] and F[i]>F[i+1]:
e.append(V[i])
f2=open("fd2.d","w")
for k in range (s):
print("For entered value",V[k],"the corresponding frequency is=",F[k],file=f2)
print("The mode of the distribution is=",e,file=f2)
f2.close()
f1=open("fd.d","w")
n=input("Enter the no. of dimention:")
n=int(n)
x=[]
for i in range (n):
s=input("Enter the value:")
s=float(s)
x.append(s)
for i in range (n):
for j in range (i+1,n):
if x[i]>x[j]:
a=x.pop(j)
x.insert(i,a)
print("The list of numbers in ascending series=",x,file=f1)
f1.close()
f1=open("fd.d","r")
V=[x[0]]
F=[]
f=1
for i in range (1,n):
if x[i]==V[-1]:
f=f+1
else:
F.append(f)
f=1
V.append(x[i])
F.append(f)
s=len(V)
e=[]
for i in range(1,s-1):
if F[i]>F[i-1] and F[i]>F[i+1]:
e.append(V[i])
f2=open("fd2.d","w")
for k in range (s):
print("For entered value",V[k],"the corresponding frequency is=",F[k],file=f2)
print("The mode of the distribution is=",e,file=f2)
f2.close()
Comments
Post a Comment