class Money: def __init__(self, dollars=0, cents=0): self.cents = (dollars * 100) + cents def __str__(self): return '$%s.%s' % (self.cents / 100, self.cents % 100) def __mul__(self, other): return Money(cents=int(self.cents * other)) item = Money(10, 50) print item print item * .0875
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