-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.py
More file actions
63 lines (54 loc) · 2.14 KB
/
Copy pathoop.py
File metadata and controls
63 lines (54 loc) · 2.14 KB
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
63
class BalanceException(Exception):
pass
class BankAccount:
def __init__(self, initialAmount, acctName):
self.balance = initialAmount
self.name = acctName
print(f"\nAccount '{self.name}' created.\nBalance = ${self.balance:.2f}")
def getBalance(self):
print(f"\nAccount '{self.name}' balance = ${self.balance:.2f}")
def deposit(self, amount):
self.balance = self.balance + amount
print(f"\nDeposit complete.")
self.getBalance()
def viableTransaction(self, amount):
if self.balance >= amount:
return
else:
raise BalanceException(
f"\nSorry, account'{self.name}' only has a balance of ${self.balance:.2f}"
)
def withdraw(self, amount):
try:
self.viableTransaction(amount)
self.balance = self.balance - amount
print("\nWithdraw complete.")
self.getBalance()
except BalanceException as error:
print(f'\nWithdraw interrupted: {error}')
def transfer(self,amount,account):
try:
print('\n*********\n\nBeginning Transfer..🚀')
self.viableTransaction(amount)
self.withdraw(amount)
account.deposit(amount)
print('\nTransfer complete! ✅\n\n**********')
except BalanceException as error:
print(f'\nTransfer interrupted. ❌{error}')
class InterestRewardsAcct(BankAccount):
def deposit(self, amount):
self.balance = self.balance + (amount * 1.05)
print("\nDeposit complete.")
self.getBalance()
class SavingsAcct(InterestRewardsAcct):
def __init__(self, initialAmount, acctName):
super().__init__(initialAmount,acctName)
self.fee = 5
def withdraw(self, amount):
try:
self.viableTransaction(amount + self.fee)
self.balance = self.balance - (amount + self.fee)
print("\nWithdraw completed.")
self.getBalance()
except BalanceException as error:
print(f'\nWithdraw Interrupted: {error}')