Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 14, 2017 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/b21faba9c1881dfb157a2cddb8f81eeb to your computer and use it in GitHub Desktop.
Save codecademydev/b21faba9c1881dfb157a2cddb8f81eeb to your computer and use it in GitHub Desktop.
Codecademy export
class BankAccount(object):
balance = 0
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 "$%.2f" % (self.balance)
def deposit(self, amount):
if amount <= 0:
print "Erroric"
return
else:
print "You deposit $%.2f" % (self.amount)
self.balance += amount
self.show_balance()
def withdraw(self, amount):
if amount <= 0:
print "Erroric"
return
else:
print "You withdraw $%.2f" % (self.amount)
self.balance -= amount
self.show_balance()
my_account = BankAccount("Lord Noah")
print my_account
my_account.show_balance()
my_account.deposit(2000)
my_account.withdraw(1000)
print my_account
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment