class Number_set: '''this class stores sets of numbers, adding values and giving their number, sum and average value, ask whether the set is empty, get the maximum added value''' def __init__(self): # constructor, builds an object (empty set) '''creates an object representing an empty set''' # define the "internal state" of the object. Variables inside each object self.__num = 0 # private variable self.__sum = 0 # private variable INFORMATION HIDING self.__max = None # private variable def add(self, val): # modifier adds a new element to the set '''adds value val to the set of numbers''' # update the internal status self.__num += 1 self.__sum += val if self.__num == 1 or val > self.__max: self.__max = val def reset(self): # modifier, restores the initial condition (empty set) '''resets object to the emty set''' self.__num = 0 self.__sum = 0 self.__max = None def get_num(self): # accessor, returns how many numbers have been added '''returns the number of added elements''' return self.__num def get_sum(self): # accessor, retuns the sum of elements '''returns the sum of added elements''' return self.__sum def empty(self): '''returns True if it is an empty set, False otherwise''' if self.__num == 0: return True else: return False def get_avg(self): # accessor, returns the average of added elements '''returns the average of added elements''' if self.__num == 0: return None else: return self.__sum/self.__num def get_max(self): '''returns the maximum value added to the set. Returns None if the set is empty''' return self.__max