Skip to content

Instantly share code, notes, and snippets.

@IanMcT
Created October 14, 2016 17:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanMcT/a2172eaeb163031f6b438ed61d1bd09c to your computer and use it in GitHub Desktop.
Save IanMcT/a2172eaeb163031f6b438ed61d1bd09c to your computer and use it in GitHub Desktop.
oop conceps
class BANK_ACCOUNT:
"""Bank account
has balance, and withdraw and deposit functions"""
def __init__(self):
self.balance = 0
def deposit(self, amount):
"""adds money to the balance"""
self.balance += amount
def __str__(self):
return "Balance is: $" + str(format(self.balance,".2f"))
class CHILDACCOUNT(BANK_ACCOUNT):
def __init__(self):
super().__init__()
def withdraw(self, amount):
if amount>20:
print('Too much money')
return False
else:
self.balance=self.balance-amount
return True
b = BANK_ACCOUNT()
print(b)
b.deposit(47.384)
print(b)
print(b.__doc__)
print(b.deposit.__doc__)
c=CHILDACCOUNT()
print(c)
c.deposit(100)
print(c)
c.withdraw(50)
print(c)
c.withdraw(20)
print(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment