from __future__ import division class Calc: result = 0.0 def __init__(self): pass def add(self, x, y): self.result = x + y return (self.result) def minus(self, x, y): self.result = x - y return (self.result) def mul(self, x, y): self.result = x * y return (self.result) def div(self, x, y): if (y != 0): self.result = x / y else: self.result = 0 return (self.result) def getLastResult(self): return (self.result) def sort(self, arrNum): if type(arrNum) is list: _arrNum = sorted(arrNum) return (_arrNum) return (None) if __name__ == '__main__': calc = Calc() print "3 + 5 = %d" % (calc.add(3, 5)) print "%d - 2 = %d" % (calc.getLastResult(), calc.minus(calc.getLastResult(), 2)) print "%d * 5 = %d" % (calc.getLastResult(), calc.mul(calc.getLastResult(), 5)) print "%d / 7 = %.2f" % (calc.getLastResult(), calc.div(calc.getLastResult(), 7)) arrNum = [5, 3, 8, 7, 4] print (calc.sort(arrNum))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question