Created
October 14, 2016 17:23
-
-
Save IanMcT/a2172eaeb163031f6b438ed61d1bd09c to your computer and use it in GitHub Desktop.
oop conceps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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