forked from Shreyasheeetal20/HACKTOBERFEST22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BankManagementSysytem.py
364 lines (313 loc) · 10.3 KB
/
BankManagementSysytem.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# Code by Atharv Patil
import mysql.connector as ship
mycon = ship.connect(user='root', passwd='1111',
host='localhost', database='project')
cursor = mycon.cursor()
print("\t\t===============================================================================")
print("\t\t\t\t\t\tBANK MANAGEMENT SYSTEM")
print("\t\t===============================================================================")
def MENU():
print("\t---------------------------")
print("\tMAIN MENU")
print("\t---------------------------")
print('\t1. Insert Record')
print('\t2. Display records as per Account number')
print('\t3. Search Record Details as per the account number')
print('\t4. Update Record')
print('\t5. Delete Record')
print('\t6. Transactions from the account')
print('\t7. Exit')
print('='*148)
def MenuTransactions():
print(" a. Debit/Withdraw from the account")
print(" b. Credit into the account")
print(" c. Back to MAIN MENU")
def Create():
try:
cursor.execute('Create table BOB( ACCNO varchar(20), NAME varchar(20), PHONE varchar(20), EMAILID varchar(50), ADDRESS varchar(50), CITY varchar(15), COUNTRY varchar(20), Balance int(10))')
cursor.fetchall()
print('Table Created')
Insert()
except:
Insert()
def Insert():
while True:
def A():
global Acc
Acc = input("Enter the Account No. ")
l = "select accno from BOB"
cursor.execute(l)
ad = cursor.fetchall()
for i in ad:
if Acc == i[0]:
print("This account already exists....")
print("Please Enter Unique Account Number")
A()
else:
pass
A()
Name = input("Enter Name: ")
def Mobile():
global Mob
Mob = input("Enter Mobile: ")
if len(Mob) == 10:
pass
else:
print("Please enter valid mobile number of 10 digits ")
Mobile()
print()
Mobile()
EmailID = input("Enter EmailID: ")
Address = input("Enter your Address: ")
City = input("Enter City: ")
Country = input("Enter your country: ")
Bal = float(input("Enter Balance: "))
Rec = [Acc, Name.upper(), Mob, EmailID.upper(), Address.upper(),
City.upper(), Country.upper(), Bal]
Cmd = 'insert into BOB values(%s,%s,%s,%s,%s,%s,%s,%s)'
cursor.execute(Cmd, Rec)
mycon.commit()
print("Account added successfully...")
tp = input("Do You Want To Enter More Records (Y/N)? ")
if tp == "N" or tp == "n":
break
def DispSortAcc():
cmd = "select * from BOB order by ACCNO"
cursor.execute(cmd)
S = cursor.fetchall()
print('*'*102)
print('ACCNO', ' NAME', ' MOBILE', ' EMAIL',
' ADDRESS', ' CITY', ' COUNTRY', ' BALANCE')
print('*'*102)
for i in S:
for j in range(len(i)):
print(i[j], end=" ")
print()
mycon.commit()
def DispSortName():
try:
cmd = "select * from BOB order by Name"
cursor.execute(cmd)
S = cursor.fetchall()
F = '%15s %15s %15s %15s %15s %15s %15s %15s'
print(F % ('ACCNO', 'NAME', 'MOBILE', 'EMAIL',
'ADDRESS', 'CITY', 'COUNTRY', 'BALANCE'))
print('*'*157)
for i in S:
for j in i:
print('%14s' % j, end=' ')
print()
print('*'*157)
except:
print("Table doesn't exists")
def DispSortBal():
try:
cmd = "select * from BOB order by Balance"
cursor.execute(cmd)
S = cursor.fetchall()
F = '%15s %15s %15s %15s %15s %15s %15s %15s'
print(F % ('ACCNO', 'NAME', 'MOBILE', 'EMAIL',
'ADDRESS', 'CITY', 'COUNTRY', 'BALANCE'))
print('*'*157)
for i in S:
for j in i:
print('%14s' % j, end=' ')
print()
print('_'*157)
except:
print("Table doesn't exists")
def DispSearchAcc():
ch = int(input('Enter the account no. to be searched: '))
cmd = 'select * from BOB where accno=%s' % (ch,)
cursor.execute(cmd)
a = cursor.fetchone()
if a != ():
f = 0
for i in a:
f += 1
print(i, end=' ')
if len(a) == f:
print()
else:
print("No record found")
def UPDATE():
A = input("Enter the Account number whose details to be changed")
cmd = "select * from BOB where accno = %s" % (A,)
cursor.execute(cmd)
S = cursor.fetchone()
print(S)
a = 0
while a == 0:
print("What do you wan to change : ")
print("\t1. Name ")
print("\t2.Mobile ")
print("\t3.Email Id ")
print("\t4. Address ")
print("\t5.City ")
print("\t6. Country ")
print("\t7. Balance ")
print("\tPress 8 for exit ")
ch = input('\t')
if ch == '1':
name = input("Enter New Name: ")
cmd = 'update BOB set name="%s" where accno=%s' % (name, A)
cursor.execute(cmd)
mycon.commit()
print("Updated name is", name)
elif ch == '2':
phone = input("Enter the new phone number: ")
cmd = 'update BOB set phone="%s" where accno=%s' % (phone, A)
cursor.execute(cmd)
mycon.commit()
print("Updated phone is ", phone)
elif ch == '3':
email = input("Enter the new email id: ")
cmd = 'update BOB set emailid="%s" where accno=%s' % (email, A)
cursor.execute(cmd)
mycon.commit()
print("Updated Email Id is ", email)
elif ch == '4':
add = input("Enter the new Address: ")
cmd = 'update BOB set address="%s" where accno=%s' % (add, A)
cursor.execute(cmd)
mycon.commit()
print("Updated Address is ", add)
elif ch == '5':
city = input("Enter the new city: ")
cmd = 'update BOB set city="%s" where accno=%s' % (city, A)
cursor.execute(cmd)
mycon.commit()
print("Updated City is ", city)
elif ch == '6':
count = input("Enter the new country: ")
cmd = 'update BOB set country="%s" where accno=%s' % (count, A)
cursor.execute(cmd)
mycon.commit()
print("Updated Country is", count)
elif ch == '7':
bal = int(input("Enter the New Balance: "))
cmd = 'update BOB set balance=%s where accno=%s' % (bal, A)
cursor.execute(cmd)
mycon.commit()
print("Updated balance is", bal)
elif ch == '8':
a = 1
else:
print("Please enter valid choice")
def Delete():
def A():
global acc
acc = input("Enter the account number: ")
l = "select accno from BOB"
cursor.execute(l)
ad = cursor.fetchall()
for i in ad:
if acc == i[0]:
break
else:
print("Sorry,This account does not exist")
A()
A()
cmd = 'delete from BOB where accno=%s' % (acc,)
print("Account deleted Successfully...")
cursor.execute(cmd)
mycon.commit()
def Debit():
def A():
global acc
acc = input("Enter the accno. from which the money is to be debited: ")
l = "select accno from BOB"
cursor.execute(l)
ad = cursor.fetchall()
for i in ad:
if acc == i[0]:
break
else:
print("Sorry,This account does not exist")
print()
A()
A()
print()
cmd = "select balance from BOB where accno=%s" % (acc,)
cursor.execute(cmd)
S = cursor.fetchone()
print("Please note that money can only be debited if the min balance is of Rs 5000")
print()
wd = int(input("How much amount to be debited: "))
if wd > S[0]:
print()
print("Not enough balance")
else:
if S[0] >= 5000:
final = S[0]-wd
cd = "update bob set balance=%s where accno=%s" % (final, acc)
cursor.execute(cd)
mycon.commit()
print("Amount Debited Successfully...")
print("Current Balance :-", final)
print()
else:
print("Your Balance is less than Rs 5000")
print("You cannot withdraw Money")
def Credit():
def A():
global acc
acc = input("Enter the accno. from which the money is to be Credited: ")
l = "select accno from BOB"
cursor.execute(l)
ad = cursor.fetchall()
for i in ad:
if acc == i[0]:
break
else:
print("Sorry,This account does not exist")
A()
A()
print()
cmd = "select balance from BOB where accno=%s" % (acc,)
cursor.execute(cmd)
S = cursor.fetchone()
wd = int(input("How much amount to be credited:"))
final = S[0]+wd
cd = "update bob set balance=%s where accno=%s" % (final, acc)
cursor.execute(cd)
mycon.commit()
print()
print("Amount Credited Successfully...")
print("Current Balance :-", final)
print()
while True:
MENU()
ch = input("Enter Your Choice: ")
if ch == "1":
Create()
elif ch == "2":
DispSortAcc()
elif ch == '3':
DispSearchAcc()
elif ch == '4':
UPDATE()
elif ch == '5':
Delete()
elif ch == '6':
while True:
MenuTransactions()
ch1 = input("Enter choice a/b/c: ")
if ch1 in ['a', 'A']:
Debit()
elif ch1 in ['b', 'B']:
Credit()
elif ch1 in ['c', 'C']:
print("Back to main menu")
break
else:
print("Invalid Choice")
elif ch == '7':
print("Exiting...")
print()
print("\t\t===============================================================================")
print("\t\t\t\t\tTHANKS FOR USING BANK MANAGEMENT SYSTEM")
print("\t\t===============================================================================")
break
else:
print("Entered Wrong Choice ")