Hi
I have a function for calculating the standard deviation of a list. I was wanting to create this as an object and inherit from pythons list object.
I'm pretty new to the whole OOP concept, can someone please have a look at my code to see why it prints an address rather than a value and where I'm messing this OOP thing up.
Thanks
I have a function for calculating the standard deviation of a list. I was wanting to create this as an object and inherit from pythons list object.
I'm pretty new to the whole OOP concept, can someone please have a look at my code to see why it prints an address rather than a value and where I'm messing this OOP thing up.
Thanks
Code:
class StandardDev(list): def __init__(self, theList): self.theList = theList def standardDev(self): import math sums = 0 n = len(self) #Calculate the mean average ma = (1/float(n))*sum(self) for i, j in enumerate(self): sums += ((self[i]-ma)**2) return round(math.sqrt((1/float(n))*(sums)),2) a = (5,6,8,9) b = StandardDev(a) print b.standardDev
Comment