Created
October 30, 2013 21:31
-
-
Save glenrobertson/7240658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MovingAverage: | |
total_sum = 0 | |
total_count = 0 | |
def add_number(self, num): | |
self.total_sum += num | |
self.total_count += 1 | |
def get_average(self): | |
return self.total_sum / self.total_count | |
def reset(self): | |
self.total_sum = 0 | |
self.total_count = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This isn't really a moving average though - same could be achieved with (psudo code, I don't know python)
In this case not really worthy of a class...