Skewness and Kurtosis

http://www.dreamincode.net/code/snippet3048.htm

 

Found a code for skewness and kurtosis. Just putting it here for reference.

from math import *
from Numeric import *
n=input("Enter the number of class:")
h=input("Enter class interval:")
sum_f=0
sum_fm=0
total1=0
total2=0
total3=0
a=zeros(n,Int)
b=zeros(n,Int)
for i in range(n):
    print "For class-%s"%(i+1)
    f=input("Frequency:")
    l=input("Lower limit:")
    u=l+h    #upper limit
    ul=(l+u)/2.0	#mean of upper and lower limit
    ful=f*ul	#multiplication of frequency and mean
    a[i]=ul
    b[i]=f
    sum_f=f+sum_f
    sum_fm=ful+sum_fm
x=sum_fm/sum_f		#arithmetic mean
for i in range(n):
    d=a[i]-x
    v1=pow(d,2)*b[i]
    v2=pow(d,3)*b[i]
    v3=pow(d,4)*b[i]
    total1=v1+total1
    total2=v1+total2
    total3=v1+total3    m2=total1/sum_f    #2nd moment
m3=total2/sum_f    #3rd moment
m4=total3/sum_f    #4th moment
s=pow(m3,2)/pow(m2,3)    #skewness
k=m4/pow(m2,2)    #kurtosis
print "The skewness is %s & kurtosis is %s"%(s,k)