-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bank_System.py
166 lines (141 loc) · 4.79 KB
/
Bank_System.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Bank Management System
import pickle
import os
import pathlib
class Account :
accNo = 0
name = ''
deposit=0
type = ''
def createAccount(self):
self.accNo= int(input("Enter the account no : "))
self.name = input("Enter the account holder name : ")
self.type = input("Ente the type of account [C/S] : ")
self.deposit = int(input("Enter The Initial amount(>=500 for Saving and >=1000 for current"))
print("\n\n\nAccount Created")
def showAccount(self):
print("Account Number : ",self.accNo)
print("Account Holder Name : ", self.name)
print("Type of Account",self.type)
print("Balance : ",self.deposit)
def depositAmount(self,amount):
self.deposit += amount
def withdrawAmount(self,amount):
self.deposit -= amount
def report(self):
print(self.accNo, " ",self.name ," ",self.type," ", self.deposit)
def getAccountNo(self):
return self.accNo
def getAcccountHolderName(self):
return self.name
def getAccountType(self):
return self.type
def getDeposit(self):
return self.deposit
def intro():
print("\t\t\t\t**********")
print("\t\t\t\tBANK MANAGEMENT SYSTEM")
print("\t\t\t\t**********")
# input()
def writeAccount():
account = Account()
account.createAccount()
writeAccountsFile(account)
def displayAll():
file = pathlib.Path("accounts.data")
if file.exists():
infile = open('accounts.data','rb')
mylist = pickle.load(infile)
for item in mylist :
print(item.accNo," ", item.name, " ",item.type, " ",item.deposit )
infile.close()
else :
print("No records to display")
def displaySp(num):
file = pathlib.Path("accounts.data")
if file.exists ():
infile = open('accounts.data','rb')
mylist = pickle.load(infile)
infile.close()
found = False
for item in mylist :
if item.accNo == num :
print("Your account Balance is = ",item.deposit)
found = True
else :
print("No records to Search")
if not found :
print("No existing record with this number")
def depositAndWithdraw(num1,num2):
file = pathlib.Path("accounts.data")
if file.exists():
infile = open('accounts.data','rb')
mylist = pickle.load(infile)
infile.close()
os.remove('accounts.data')
for item in mylist :
if item.accNo == num1 :
if num2 == 1 :
amount = int(input("Enter the amount to deposit : "))
item.deposit += amount
print("Your account is updated")
elif num2 == 2 :
amount = int(input("Enter the amount to withdraw : "))
if amount <= item.deposit :
item.deposit -=amount
print("Your account is updated")
else :
print("You cannot withdraw larger amount")
else :
print("No records to Search")
outfile = open('newaccounts.data','wb')
pickle.dump(mylist, outfile)
outfile.close()
os.rename('newaccounts.data', 'accounts.data')
def writeAccountsFile(account) :
file = pathlib.Path("accounts.data")
if file.exists ():
infile = open('accounts.data','rb')
oldlist = pickle.load(infile)
oldlist.append(account)
infile.close()
os.remove('accounts.data')
else :
oldlist = [account]
outfile = open('newaccounts.data','wb')
pickle.dump(oldlist, outfile)
outfile.close()
os.rename('newaccounts.data', 'accounts.data')
# start of the program
ch=''
num=0
intro()
while ch != 8:
os.system("cls")
print("\tMAIN MENU")
print("\t1. NEW ACCOUNT")
print("\t2. DEPOSIT AMOUNT")
print("\t3. WITHDRAW AMOUNT")
print("\t4. BALANCE ENQUIRY")
print("\t5. ALL ACCOUNT HOLDER LIST")
print("\t6. EXIT")
ch=int(input("enter your choice:"))
if ch == 1:
writeAccount()
elif ch ==2:
num = int(input("\tEnter The account No. : "))
depositAndWithdraw(num, 1)
elif ch ==3:
num = int(input("\tEnter The account No. : "))
depositAndWithdraw(num, 2)
elif ch ==4:
num = int(input("\tEnter The account No. : "))
displaySp(num)
elif ch ==5:
displayAll();
elif ch ==6:
print("\tThanks for using Bank Management System")
break
else :
print("Invalid choice")
ch = input("Enter any key press : ")