- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingMiniProject.py
More file actions
Latest commit
106 lines (92 loc) · 3.67 KB
/
Copy pathBankingMiniProject.py
File metadata and controls
106 lines (92 loc) · 3.67 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
importpickle
classBank:
def__init__(self):
self.accounts= {}
defcreate_account(self, account_number, name):
ifaccount_numberinself.accounts:
print("Account with that name already exists.")
else:
self.accounts[account_number] =0
print(f"Account created for {name}.")
defdeposit(self, account_number, name, amount):
ifaccount_numberinself.accounts:
ifamount>0:
self.accounts[account_number] +=amount
print(f"Rs.{amount} deposited into {name}'s account.")
else:
print("Invalid amount. Please enter a positive value.")
else:
print(f"No account found for {name}.")
defwithdraw(self, account_number, name, amount):
ifaccount_numberinself.accounts:
ifself.accounts[account_number] >=amount>0:
self.accounts[account_number] -=amount
print(f"Rs.{amount} withdrawn from {name}'s account.")
else:
print("Insufficient funds.")
else:
print(f"No account found for {name}.")
defcheck_balance(self, account_number, name):
ifaccount_numberinself.accounts:
balance=self.accounts[account_number]
print(f"Account balance for {name}: Rs.{balance}")
else:
print(f"No account found for {name}.")
defclose_account(self, account_number, name):
ifaccount_numberinself.accounts:
delself.accounts[account_number]
print(f"Account closed successfully for {name}.")
else:
print(f"Account {name} not found.")
defsave_data(self, bank_file):
withopen(bank_file, 'wb') asfile:
pickle.dump(self.accounts, file)
print("Data saved successfully.")
defload_data(self, bank_file):
try:
withopen(bank_file, 'rb') asfile:
self.accounts=pickle.load(file)
print("Data loaded successfully.")
exceptFileNotFoundError:
print("No previous data found.")
bank=Bank()
whileTrue:
print("1. Create Account")
print("2. Deposit")
print("3. Withdraw")
print("4. Check Balance")
print("5. Close Account ")
print("6. Save Data")
print("7. Load Data")
print("8. Exit")
choice=input("Enter your choice: ")
ifchoice=="1":
account_number=input("Enter account number:")
name=input("Enter account holder name: ")
bank.create_account(account_number, name)
elifchoice=="2":
account_number=input("Enter account number: ")
name=input("Enter account holder name: ")
amount=float(input("Enter deposit amount: "))
bank.deposit(account_number, name, amount)
elifchoice=="3":
account_number=input("Enter account number: ")
name=input("Enter account holder name: ")
amount=float(input("Enter withdrawal amount: "))
bank.withdraw(account_number, name, amount)
elifchoice=="4":
account_number=input("Enter account number: ")
name=input("Enter account holder name: ")
bank.check_balance(account_number, name)
elifchoice=="5":
account_number=input("Enter account number:")
name=input("Enter account holder name: ")
bank.close_account(account_number, name)
elifchoice=="6":
bank_file=input("Enter the filename to save the data: ")
bank.save_data(bank_file)
elifchoice=="7":
bank_file=input("Enter the filename to load the data: ")
bank.load_data(bank_file)
else:
print("Invalid choice")