-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank_accounts.py
62 lines (52 loc) · 1.86 KB
/
bank_accounts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class BalanceException(Exception):
pass
class BankAccount:
def __init__(self, accountName, initialAmt):
self.name = accountName
self.balance = initialAmt
print(f"\nAccount {self.name} created.\nBalance = ${self.balance:.2f}")
def getBalance(self):
print(f"\nAccount {self.name} has balance of ${self.balance:.2f}")
def deposit(self, amount):
self.balance += amount
print(f"\n${amount} has been deposited.")
self.getBalance()
def viableTransaction(self,amount):
if self.balance >= amount:
return
else:
raise BalanceException(f"Sorry, {self.name} doesn't have sufficient money in your account.")
def withdraw(self, amount):
try:
self.viableTransaction(amount)
self.balance -= amount
print(f"Withdraw done.")
self.getBalance()
except BalanceException as error:
print(f"\n {error}")
def transfer(self, amount, account):
try:
print("Beginning Transfer 🚀".center(75, "*"))
self.viableTransaction(amount)
self.withdraw(amount)
account.deposit(amount)
print(f"\n Transfer Completed. ✔")
except BalanceException as error:
print(f"\n {error} ❌")
class InterestRewardsAcct(BankAccount):
def deposit(self, amount):
self.balance += amount + (amount * 0.5)
print("\n Deposit completed")
self.getBalance()
class SavingsAccount(InterestRewardsAcct):
def __init__(self, accountName,initialAmt):
super().__init__(accountName, initialAmt)
self.fee = 5
def withdraw(self, amount):
try:
self.viableTransaction(amount + self.fee)
self.balance -= (amount + self.fee)
print(f"\nWithdraw completed.")
self.getBalance()
except BalanceException as error:
print(f"\n {error} ❌")