class BankAccount(object): balance = 0 def __init__(self, name): self.name = name def __repr__(self): print "%s has a balance of $%.2f" % (self.name, self.balance) def show_balance(self): print "Balance: $%.2f" % (self.balance) def deposit(self, amount): if amount <= 0: print "That is not an acceptable amount to deposit" return else: self.balance += amount print "Deposited $%.2f" % (amount) print self.show_balance() def withdraw(self, amount): if amount <= 0 or amount > self.balance: print "That is not an acceptable amount to withdraw" return else: self.balance -= amount print "Withdrew $%.2f" % (amount) print self.show_balance() NameOne = BankAccount("Named") print NameOne NameOne.show_balance() NameOne.deposit(2000) NameOne.withdraw(1000) print NameOne
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