-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank Account Management System with Transaction Analysis.py
More file actions
134 lines (112 loc) · 4.09 KB
/
Copy pathBank Account Management System with Transaction Analysis.py
File metadata and controls
134 lines (112 loc) · 4.09 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Bank Account Management System with Transaction Analytics
import matplotlib.pyplot as plt
import numpy as np
class BankAccount:
# Create the account object
def __init__(self, name, pin, balance=0):
self.name = name
self.balance = balance
self.pin = pin
self.history = []
# Deposit funds
def deposit(self, amount):
self.balance += amount
self.history.append(f"Deposited ${amount}")
print(f"Amount deposited: ${amount}. New balance: ${self.balance}")
# Withdraw funds
def withdrawal(self, amount):
if amount <= self.balance:
self.balance -= amount
self.history.append(f'Withdrew ${amount}')
print(f"Amount withdrawn: ${amount}. New balance: ${self.balance}")
else:
print("Insufficient funds!")
# Show balance
def show_balance(self):
print(f"Account '{self.name}' balance: ${self.balance}")
# Change PIN
def change_pin(self):
new_pin = input("Enter new 4-digit PIN: ")
if new_pin == self.pin:
print("You cannot use the same PIN.")
elif not new_pin.isdigit() or len(new_pin) != 4:
print("PIN must be exactly 4 digits.")
else:
self.pin = new_pin
print("PIN successfully changed.")
# Change account name
def new_account_name(self):
new_name = input("Enter new account name: ")
if new_name == self.name:
print("You cannot use the same account name.")
else:
self.name = new_name
print("Account name successfully changed.")
# Show transaction history
def transaction_history(self):
if not self.history:
print("No transactions have been made!")
else:
print("\n*** Transaction History ***")
for x in self.history:
print(x)
# Show transaction trend (Option 7)
def transaction_trend(self):
deposits = []
withdrawals = []
for entry in self.history:
if "Deposited" in entry:
deposits.append(float(entry.split("$")[1]))
elif "Withdrew" in entry:
withdrawals.append(float(entry.split("$")[1]))
plt.figure(figsize=(8,5))
plt.plot(range(1, len(deposits)+1), deposits, marker='o', label='Deposits')
plt.plot(range(1, len(withdrawals)+1), withdrawals, marker='o', label='Withdrawals')
plt.title(f"Transaction Trend for {self.name}")
plt.xlabel("Transaction Number")
plt.ylabel("Amount ($)")
plt.legend()
plt.grid(True)
# Set x-axis ticks to increment by 1
max_x = max(len(deposits), len(withdrawals))
plt.xticks(np.arange(1, max_x + 1, 1))
# Set y-axis ticks to show all transaction amounts
all_amounts = deposits + withdrawals
if all_amounts: # only if there are transactions
plt.yticks(sorted(all_amounts))
plt.show()
# Main Program
name = input("Enter your account name: ")
pin = input("Enter 4-digit PIN: ")
account = BankAccount(name, pin)
# Authentication
entered_pin = input("Enter your PIN to access account: ")
if entered_pin != account.pin:
print("Incorrect PIN! Access denied.")
exit()
# Main menu loop
while True:
print("\n1. Deposit 2. Withdraw 3. Show balance 4. Show Transaction History")
print("5. Change PIN 6. Change Account Name 7. Show Transaction Trend 8. Exit")
choice = input("Choose an option: ")
if choice == "1":
amt = float(input("Enter amount to deposit: "))
account.deposit(amt)
elif choice == "2":
amt = float(input("Enter amount to withdraw: "))
account.withdrawal(amt)
elif choice == "3":
account.show_balance()
elif choice == "4":
account.transaction_history()
elif choice == "5":
account.change_pin()
elif choice == "6":
account.new_account_name()
elif choice == "7":
account.transaction_trend()
elif choice == "8":
print("Exiting... Goodbye!")
break
else:
print("Invalid choice. Try again.")