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): x = raw_input("Enter your deposit: ") if x <= 0: print "That is not an acceptable amount to deposit" return else: self.balance = x print "Done" NameOne = BankAccount("Named") NameOne.__repr__() NameOne.show_balance() NameOne.deposit() NameOne.show_balance()
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