Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 11, 2019 16:19
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/b2c84b960cd11373b6ac9b1aca46ef69 to your computer and use it in GitHub Desktop.
Save codecademydev/b2c84b960cd11373b6ac9b1aca46ef69 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):
print "This account belongs to %s and has a balance of $ %.2f" % (self.name, self.balance)
def show_balance(self):
print "Your total balance is $%.2f" % self.balance
def deposit(self, amount):
if amount <= 0 :
print "Invalid deposit"
return
else :
print "You are depositing $ %.2f" % amount
self.balance += amount
self.show_balance()
def withdraw(self, amount):
if amount > self.balance :
print "Error, you can't withdraw more than you have dummy!"
return
else :
print "You are withdrawing $%.2f" % amount
self.balance -= amount
self.show_balance()
my_account = BankAccount("Mike")
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