-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
executable file
·182 lines (169 loc) · 4 KB
/
main.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
#Bank management System
import pickle
import os
class Customer:
def __init__(self,A):
self.name=input("Enter Name: ")
self.type=input("Type of Account s/c?: ")
self.amount=int(input("Enter Amount: "))
while True:
if self.type=='s':
if self.amount<5000:
print("Min 5000 required")
self.amount=int(input("Please Enter amount again: "))
else:
break
if self.type=='c':
if self.amount<2000:
print("Min 2000 required")
self.amount=int(input("Please Enter amount again: "))
else:
break
self.accountNo=A
print("Your Account No. is:",self.accountNo)
def Display(self):
print("{:<15} {:<15} {:<15} {:<15}".format(self.accountNo,self.name,self.type,self.amount))
def createAccount():
try:
file=open('bank.bin','rb')
while True:
t=pickle.load(file)
A=t.accountNo
except FileNotFoundError as e:
A=121000
except EOFError as e:
A=A+1
file.close()
file=open('bank.bin','ab')
s=Customer(A)
pickle.dump(s,file)
file.close()
option()
def ViewAllAccount():
try:
file=open('bank.bin','rb')
print("{:<15} {:<15} {:<15} {:<15}".format('Account No.','Name','Type','Amount'))
while True:
t=pickle.load(file)
t.Display()
except FileNotFoundError as e:
print("\nThere Are No Record")
except EOFError as e:
file.close()
option()
def Deposit():
file=open('bank.bin','rb')
file1=open('tmp.bin','wb')
x=int(input("Enter Bank Account: "))
try:
while True:
t=pickle.load(file)
if t.accountNo==x:
cr=int(input("Enter Deposit Amount: "))
t.amount=t.amount+cr
pickle.dump(t,file1)
except:
pass
finally:
file.close()
file1.close()
os.remove('bank.bin')
os.rename('tmp.bin','bank.bin')
option()
def Withdraw():
file=open('bank.bin','rb')
file1=open('tmp.bin','wb')
x=int(input("Enter Bank Account: "))
try:
while True:
t=pickle.load(file)
if t.accountNo==x:
dr=int(input("Enter Withdraw Amount: "))
if t.type=='s':
while True:
if t.amount-dr<5000:
print("Saving Account Balance can't be below 5000")
dr=int(input("Enter Withdraw Amount: "))
else:
t.amount=t.amount-dr
break
if t.type=='c':
while True:
if t.amount-dr<2000:
print("Currunt Account Balance can't be below 2000")
dr=int(input("Enter Withdraw Amount: "))
else:
t.amount=t.amount-dr
break
pickle.dump(t,file1)
except:
pass
finally:
file.close()
file1.close()
os.remove('bank.bin')
os.rename('tmp.bin','bank.bin')
option()
def Update():
file=open('bank.bin','rb')
file1=open('tmp.bin','wb')
x=int(input("Enter Bank Account: "))
try:
while True:
t=pickle.load(file)
if t.accountNo==x:
name=input("Update Name: ")
t.name=name
pickle.dump(t,file1)
except:
pass
finally:
file.close()
file1.close()
os.remove('bank.bin')
os.rename('tmp.bin','bank.bin')
option()
def Search():
file=open('bank.bin','rb')
x=int(input("Enter Bank Account: "))
try:
while True:
t=pickle.load(file)
if t.accountNo==x:
print("\nName:",t.name)
print("Account Type:",t.type)
print("Amount:",t.amount)
print("Account No.:",t.accountNo)
break
except:
pass
finally:
file.close()
option()
def Exit():
pass
def option():
print()
print("What Do You Wanna Do\n1. Create Account\n2. View all Account\n3. Deposit\n4. Withdraw\n5. Update\n6. Search\n7. Exit")
n=int(input())
if n==1:
createAccount()
elif n==2:
ViewAllAccount()
elif n==3:
Deposit()
elif n==4:
Withdraw()
elif n==5:
Update()
elif n==6:
Search()
elif n==7:
Exit()
else:
print("Invalid option")
print("Try again")
option()
s="BANKING MANAGEMENT SYSTEM"
print(s.center(45,'*'))
option()