def mean(ls):
avg=0
sum0=0
counter=0
for i in ls:
sum0+=i
counter+=1
avg=sum0/counter
return avg
def median(ls):
ls.sort()
if (len(ls)%2==0):
Median=(ls[int(len(ls)/2)-1]+ls[int((len(ls)/2))])/2
else:
Median=ls[int((len(ls))/2)]
return Median
def geometric_mean(ls):
multi=1
counter=0
for i in ls:
if(i<0):
return "the list contains negative values"
i=abs(i)
multi*=i
counter+=1
Geometric_mean=(multi)**(1/counter)
return Geometric_mean
def percentile(ls,ls1):
N=0
n=0
ls.sort()
for i in ls:
N+=1
if(i!=ls1):
n+=1
else:
c=n
if(n==N):
return "the value entered is not in the list"
if(0.25*N-int(0.25*N)>0):
n25th=int(0.25*N+1)
else:
n25th=0.25*N
if(0.5*N-int(0.5*N)>0):
n50th=int(0.5*N+1)
else:
n50th=int(0.5*N)
if(0.75*N-int(0.75*N)>0):
n75th=int(0.75*N+1)
else:
n75th=0.75*N
n100th=N
if(c<=n25th):
return "in the 25th percentile"
else:
if(c<=n50th):
return "in the 50th percentile"
else:
if(c<=n75th):
return "in the 75th percentile"
else:
return "in the 100th percentile"
def data_range(ls):
ls.sort()
R=max(ls)-min(ls)
return R
def variance(ls):
m=len(ls)
sum1=0
for i in ls:
sum1+=(i-mean(ls))**2
var=sum1/m
std=(var)**(0.5)
return var
def std(ls):
m=len(ls)
sum1=0
for i in ls:
sum1+=(i-mean(ls))**2
var=sum1/m
std=(var)**(0.5)
return std
def Frequency_Tables(ls):
count = 0
FreqTable = {}
for x in ls:
for i in ls:
if i == x:
count+=1
if x!=ls[0]:
count=count-1
dic = {x:count}
FreqTable.update(dic)
count=1
return FreqTable