class BankAccount(object): balance = 50 def __init__(self, name): self.name = name def __repr__(self): return "%s's account. Balance: $%.2f" % (self.name, self.balance) def show_balance(self): print "%s's balance: $%.2f" % (self.name, self.balance) def deposit(self, amount): if amount <= 0: print "Error! Invalid deposit" return else: print "%s is depositing $%.2f" % (self.name, amount) self.balance += amount self.show_balance() def withdraw(self, amount): if amount > self.balance: print "Error! You Don't have Enough Money." return else: print "%s is withdrawing $%.2f" % (self.name, amount) self.balance -= amount self.show_balance() x=BankAccount("Jason") print x x.show_balance print x
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