-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount.py
More file actions
108 lines (96 loc) · 4.39 KB
/
Copy pathaccount.py
File metadata and controls
108 lines (96 loc) · 4.39 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 🏦 Banking System Using Inheritance
# -- Parent Class Creation --
class Account:
def __init__(self, account_holder, account_number, balance):
self.account_holder = account_holder
self.account_number = account_number
self.balance = balance
self.transactions = []
statement = f"Account Created | Initial Balance ₹{self.balance}"
self.transactions.append(statement)
def deposit(self, amount):
if amount > 0:
self.balance += amount
print(f"₹{amount} deposited successfully.")
print("Current Balance:", self.balance)
statement = f"Deposited ₹{amount} | Balance ₹{self.balance}"
self.transactions.append(statement)
else:
print("Invalid amount, Amount must be greater than 0")
def show_balance(self):
print("Current Balance:", self.balance)
statement = f"Balance Checked | Balance ₹{self.balance}"
self.transactions.append(statement)
def show_account_details(self):
print("====== Account Details ======")
print(f"Account Holder : {self.account_holder}")
print(f"Account Number : {self.account_number}")
print(f"Current Balance : ₹{self.balance}")
def transaction_history(self):
print("====== Transaction History ======")
print(" (Last five) \n")
print("Total Transactions :", len(self.transactions) ,"\n")
if not self.transactions:
print("No transaction history available.")
else:
if len(self.transactions) <= 5:
serial_no = 0
for transaction in self.transactions:
serial_no += 1
print(f"{serial_no}. {transaction}")
else:
start = len(self.transactions) - 5
serial_no = 0
for i in range(start, start +5):
serial_no += 1
print(f"{serial_no}. {self.transactions[i]}")
# -- Child Class Creation --
class SavingsAccount(Account):
def __init__(self, account_holder, account_number, balance, interest_rate):
super().__init__(account_holder, account_number, balance)
self.interest_rate = interest_rate
def add_interest(self):
interest_amount = self.balance * (self.interest_rate / 100)
print(f"Interest: {self.interest_rate}%")
print(f"Interest Amount: {interest_amount}")
self.balance += interest_amount
print("Current Balance:", self.balance)
statement = f"Interest Added: ₹{interest_amount}/- | Balance ₹{self.balance}"
self.transactions.append(statement)
def withdraw(self, amount):
if amount > 0:
if amount <= self.balance:
self.balance -= amount
print(f"₹{amount} debited successfully.")
print("Current Balance:", self.balance)
statement = f"Withdrawn: ₹{amount}/- | Balance ₹{self.balance}"
self.transactions.append(statement)
else:
print("Insufficient Balance")
else:
print("Invalid amount, Amount must be greater than 0")
def show_account_details(self):
super().show_account_details()
print(f"Account Type : Savings Account")
print(f"Interest Rate : {self.interest_rate}%")
# -- Child Class Creation --
class CurrentAccount(Account):
def __init__(self, account_holder, account_number, balance, overdraft_limit):
super().__init__(account_holder, account_number, balance)
self.overdraft_limit = overdraft_limit
def withdraw(self, amount):
if amount > 0:
if amount <= self.balance + self.overdraft_limit:
self.balance -= amount
print(f"₹{amount} debited successfully.")
print("Current Balance:", self.balance)
statement = f"Withdrawn: ₹{amount}/- | Balance ₹{self.balance}"
self.transactions.append(statement)
else:
print("Insufficient Balance including Overdraft limit")
else:
print("Invalid amount, Amount must be greater than 0")
def show_account_details(self):
super().show_account_details()
print(f"Account Type : Current Account")
print(f"Overdraft Limit : ₹{self.overdraft_limit}")