forked from keshavsingh4522/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanking.py
195 lines (193 loc) · 4.39 KB
/
banking.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
import pickle
import os
class Account:
def __init__(self,id=10000000):
self.type=input('what type of Account you Want to open? S(min 5000) or C(min 10000) :').upper()
self.name=input('Enter name: ')
self.id=id
while True:
self.amount=int(input('Enter Amount: '))
if self.type in ('s','S'):
if self.amount<5000:
print('Enter Amount Again')
continue
else:
break
if self.type in ('c','C'):
if self.amount<10000:
print('Enter Amount Again')
continue
else:
break
def display(self):
print('{:<20}{:<20}{:<20}{:<20}'.format(self.id,self.name,self.type,self.amount))
#create account
def CreateAccount():
try:
file=open('keshav.bin','rb')
while True:
p=pickle.load(file)
except FileNotFoundError as e:
file1=open('keshav.bin','ab')
s=Account()
pickle.dump(s,file1)
file1.close()
except EOFError as e:
file1=open('keshav.bin','ab')
p.id+=1
print(p.id)
s=Account(p.id)
pickle.dump(s,file1)
file1.close()
#display function
def DisplayFile():
file=open('keshav.bin','rb')
print('{:<20}{:<20}{:<20}{:<20}'.format('id','name','type','amount'))
try:
while True:
p=pickle.load(file)
p.display()
except Exception as e:
print(e)
else:
file.close()
#deposit money
def Deposit():
file=open('keshav.bin','rb+')
file1=open('temp.bin','wb')
n=int(input('enter id ex. 10000000: '))
money=int(input('enter money to deposit: '))
try:
while True:
p=pickle.load(file)
if p.id==n:
p.amount+=money
pickle.dump(p,file1)
except:
file.close()
file1.close()
finally:
os.remove('keshav.bin')
os.rename('temp.bin','keshav.bin')
#withdraw money
def Withdraw():
def main_money():
def avail_money():
money=int(input('enter money in multiple of 100 200 500 2000: '))
l=[100,200,500,2000]
for i in l:
if money%i==0:
return money
else:
continue
else:
print("u cant withdraw money ")
return False
while True:
r=avail_money()
if r==False:
print('failed')
continue
else:
return r
def load_money(file,file1):
while True:
p=pickle.load(file)
if p.id==n:
while True:
money=main_money()
if p.amount<money:
print("insufficient balance!")
continue
else:
if p.type=='C':
if p.amount-money>=10000:
p.amount-=money
print('process completed successfully !')
break
else:
print("\t can't withdraw money","\n\t your current account limit is 10000","\n\t you can withraw max: ",p.amount-10000)
continue
if p.type=='S':
if p.amount-money>=5000:
p.amount-=money
print('process completed successfully !')
break
else:
print("\tcan't withdraw","\n\t your current account limit is 5000","\n\t you can withraw max: ",p.amount-5000)
continue
pickle.dump(p,file1)
file=open('keshav.bin','rb+')
file1=open('temp.bin','wb')
n=int(input('enter id ex. 10000000: '))
try:
load_money(file,file1)
except:
file.close()
file1.close()
finally:
os.remove('keshav.bin')
os.rename('temp.bin','keshav.bin')
#update your account
def Update():
file=open('keshav.bin','rb+')
file1=open('temp.bin','wb')
n=int(input('enter id ex. 10000000: '))
name=input('Enter new name: ')
#type=input('Enter type of account: ').upper()
try:
while True:
p=pickle.load(file)
if p.id==n:
p.name=name
pickle.dump(p,file1)
except:
file.close()
file1.close()
finally:
os.remove('keshav.bin')
os.rename('temp.bin','keshav.bin')
#search your account
def Search():
file=open('keshav.bin','rb')
n=int(input('enter id ex. 10000000: '))
try:
while True:
p=pickle.load(file)
if p.id==n:
print(' {:*>35} {:*<35}'.format('start detail of account: ',p.name))
print('id: ',p.id,'\nname: ',p.name,'\ntotal balance: ',p.amount,'\ntype: ',p.type)
print(' {:*>35} {:*<35}'.format(' end detail of account: ',p.name))
break
except:
file.close()
else:
file.close()
#
print("{:*^70}".format(' Banking Management System '),end='\n'*3)
def Choise():
print('What Do You Wanna Do?')
print('1.Create Account')
print('2.View all Accounts')
print('3.Deposit')
print('4.Withdraw')
print('5.Update')
print('6.Search')
print('7.Exit')
return int(input('Enter your choise here: '))
while True:
i=Choise()
if i==1:
CreateAccount()
if i==2:
DisplayFile()
if i==3:
Deposit()
if i==4:
Withdraw()
if i==5:
Update()
if i==6:
Search()
if i==7:
break