You are viewing a single comment's thread from:

RE: A tiny OOP challenge (Python, Java, C++, any language with class) /

in #programming8 years ago

In Python (my personal favorite...also check out sage and https://www.cocalc.com), here's how I would do it:


class Averager:
        l = []
        def add(self,a):
                self.l.append(a)
        def getAverage(self):
                return sum(self.l)/float(len(self.l))
        def getSum(self):
                return sum(self.l)
        def getNum(self):
                return len(self.l)
        def reset(self):
                self.l = []

Sort:  

Same sort of list comprehensions as C# :) Class looks similar in implementation as well.

Coin Marketplace

STEEM 0.09
TRX 0.30
JST 0.035
BTC 111135.68
ETH 3940.56
USDT 1.00
SBD 0.59