You are viewing a single comment's thread from:

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

in #programming7 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.17
TRX 0.16
JST 0.029
BTC 76095.48
ETH 2918.89
USDT 1.00
SBD 2.65