我有一门课程可以计算可能会改进的移动平均线。平均窗口的大小必须灵活。它目前通过设置窗口大小然后发送更新来工作:
twoday = MovingAverage(2) # twoday.value is None
twoday = twoday.update(10) # twoday.value is None
twoday = twoday.update(20) # twoday.value == 15
twoday = twoday.update(30) # twoday.value == 25
我认为如果它更像这样工作会很酷:
twoday = MovingAverage(2) # twoday is None
twoday += 10 # twoday is None
twoday += 20 # twoday == 15
twoday += 30 # twoday == 25
这是愚蠢的吗?是否可以?