I have a statistics.py
file which has some methods for the class Statistics. Here is how it looks:
class Statistics(object):
def __init__(self):
self.__count = 0 # how many data values seen so far
self.__avg = 0 # the running average so far
def add(self, value):
self.__count += 1
diff = value - self.__avg # convenience
self.__avg += diff / self.__count
def mean(self):
return self.__avg
def count(self):
return self.__count
I need to add two more methods to this
- maximum() which returns the maximum value ever recorded by the Statistics object and none if no values are seen.
- minimum() which returns the minimum value ever recorded by the Statistics object and none if no values are seen.
I tried using max() and min() functions couldn't include them properly. Any help where I can rectify my mistake? Here is how that looked:
class Statistics(object):
def __init__(self):
self.__count = 0 # how many data values seen so far
self.__avg = 0 # the running average so far
self.__max= 0
self.__max=max(value)
def add(self, value):
self.__count += 1
diff = value - self.__avg # convenience
self.__avg += diff / self.__count
def mean(self):
return self.__avg
def count(self):
return self.__count
def maximum(self):
return self.__max