我被告知要创建一个输出大小、最小值、最大值等的类,而不使用列表,并且属性主要位于 def add 中。我的属性在大多数情况下都可以正常工作,但由于某种原因我不能得到最低限度。谁能在正确的方向上给我一个快速的推动,并告诉我我是否走在正确的道路上?
class Dataset(object):
def __init__(self):
self.totalScore=0
self.countScore=0
self._highest=0
self._lowest=0
self.dev=0
self.mean=0
def add(self, score):
self.countScore= self.countScore + 1
self.totalScore= self.totalScore + score
self.mean=self.totalScore/self.countScore
self.dev=self.mean - score
if score > self._highest:
self._highest = score
if score < self._lowest:
self._lowest = score
def size(self):
return(self.countScore)
def min(self):
return (self._lowest)
def max(self):
return (self._highest)
我的结果是这样的:
This is a program to compute the min, max, mean and
standard deviation for a set of numbers.
Enter a number (<Enter> to quit): 50
Enter a number (<Enter> to quit): 60
Enter a number (<Enter> to quit):
Summary of 2 scores.
Min: 0
Max: 60.0
Mean: 55.0
Standard Deviation: 7.0710678118654755