-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatm.py
383 lines (317 loc) · 17.4 KB
/
atm.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
""""importing libraries"""
import random
import time
import os
import re
"""In Customer class, dict[str,list] is defined for putting customer data
such as ; name, surname, password, identity, balance. Also with using different methods under Customer class
some operation have been applied"""
class Customers:
"""This is the initial method of the customer class"""
def __init__(self):
self.customer_list = {"name": [], "surname": [], "password": [], "identity": [], "balance": []}
"""When this method is called, identity and balance occurs, name, surname and password are taken as parameter
After password parameter sends to the choosing_password method to be controlled for validation """
def create_customers(self, name, surname, password):
while True:
flag = 0
self.identity = str(random.randint(10000000, 99999999))
self.balance = 0
self.name = name
self.surname = surname
self.password = self.choosing_password(password)
if not bool(self.password):
flag = -1
return flag
elif flag == 0:
return flag
"""This method adds the customer information to the customer list"""
def add_customer(self):
self.customer_list["name"].append(self.name)
self.customer_list["surname"].append(self.surname)
self.customer_list["password"].append(self.password)
self.customer_list["identity"].append(self.identity)
self.customer_list["balance"].append(self.balance)
"""This method removes the chosen customer from the customer list
after controlling whether chosen customer is exist or not """
def remove_customer(self, remove_name, remove_surname):
for i in self.customer_list["name"]:
if remove_name == i:
for k in self.customer_list["surname"]:
index = self.customer_list["surname"].index(k)
if remove_surname == k:
self.customer_list["name"].pop(index)
self.customer_list["surname"].pop(index)
self.customer_list["password"].pop(index)
self.customer_list["identity"].pop(index)
self.customer_list["balance"].pop(index)
wait(3)
print("Your operation completed")
"""This method controls whether chosen customer is exist or not and send remove_name and remove_surname to
remove_customer method as parameters"""
def is_there_customer(self, remove_name, remove_surname):
flag = 0
for i in self.customer_list["name"]:
if remove_name == i:
for k in self.customer_list["surname"]:
if remove_surname == k:
self.remove_customer(remove_name, remove_surname)
return flag
"""This method controls name, surname and password in customer list for sign in"""
def entrance_control(self, entrance_name, entrance_surname, entrance_password):
for i in self.customer_list["name"]:
if entrance_name == i:
for k in self.customer_list["surname"]:
if entrance_surname == k:
for j in self.customer_list["password"]:
if entrance_password == j:
return True
"""This method defines some conditions to customers' password definition"""
def choosing_password(self, entrance_password):
flag = 0
while True:
if len(entrance_password) < 8:
flag = -1
break
elif not re.search("[a-z]", entrance_password):
flag = -1
break
elif not re.search("[A-Z]", entrance_password):
flag = -1
break
elif not re.search("[0-9]", entrance_password):
flag = -1
break
elif not re.search("[-_!@]", entrance_password):
flag = -1
break
elif re.search("\s", entrance_password):
flag = -1
break
else:
flag = 0
print("Valid password")
return entrance_password
if flag == -1:
print("Invalid password")
""""This method controls the name and surname of customer who the money will transfer to in money transfer part """
def money_transfer_validation(self, name, surname):
for i in self.customer_list["name"]:
if name == i:
for k in self.customer_list["surname"]:
if surname == k:
return True
""""This method keeps wait after some operations """
def wait(n):
str = "Your transaction is running"
point = "."
print(str, end="")
for i in range(n):
os.system('cls')
print(point)
time.sleep(0.5)
point += "."
def main():
customer = Customers()
while True:
print("-----------------------------\n"
"WELCOME TO THE BANK SIMULATOR\n"
"-----------------------------\n"
"Please choose your operation \n"
"=============================\n"
"[1] Sign in\n"
"[2] Sign up\n"
"[3] Management")
selection = input("")
if selection == "1":
entrance_name = input("Name:")
entrance_surname = input("Surname:")
entrance_password = input("Password:")
if customer.entrance_control(entrance_name, entrance_surname, entrance_password):
while True:
index = int(customer.customer_list["password"].index(entrance_password))
print("Welcome..{}\t{} \n"
"Chose your operation \n"
"-----------------------\n"
"[1] Account information\n"
"[2] Withdraw money \n"
"[3] Deposit money \n"
"[4] Money transfer \n"
"[Q or q] Quit \n".format(entrance_name.title(), entrance_surname.upper()))
selection = input()
if selection == "q" or selection == "Q":
break
elif selection == "1":
while True:
print("Name: {} \n"
"Surname:{} \n"
"Password:{} \n"
"Identity no:{} \n"
"Balance:{}".format(customer.customer_list["name"][index], customer.customer_list["surname"][index],
customer.customer_list["password"][index], customer.customer_list["identity"][index],
customer.customer_list["balance"][index]))
input("to menu press enter")
break
elif selection == "2":
while True:
wd_money = int(input("Write the the amount of money that you want to withdraw"))
if customer.customer_list["balance"][index] < wd_money:
wait(3)
print("You don not have enough money to apply this operation")
input("to menu press enter")
break
elif customer.customer_list["balance"][index] > wd_money:
customer.customer_list["balance"][index] -= wd_money
wait(3)
print("Operation completed")
input("to menu press enter")
break
elif customer.customer_list["balance"][index] == wd_money:
selection = input("You are about to withdraw all your money are you sure? [yes/y][no/n]")
if selection == "n" or selection == "N":
print("Operation is cancelling...")
input("to menu press enter")
break
elif selection == "y" or selection == "Y":
customer.customer_list["balance"][index] -= wd_money
wait(3)
print("Operation completed")
input("to menu press enter")
break
elif selection != "y" or selection != "Y" or selection != "n" or selection != "N":
while True:
print("Please press valid button")
break
elif selection == "3":
while True:
deposit = int(input("Enter the amount that you want to deposit:"))
customer.customer_list["balance"][index] += deposit
wait(3)
print("Operation completed")
input("to menu press enter")
break
elif selection == "4":
while True:
print("To whom do you want to send money?")
name = input("Name:")
surname = input("Surname:")
if customer.money_transfer_validation(name, surname):
index_transfer = int(customer.customer_list["surname"].index(surname))
if index_transfer != index:
try:
transfer_money = int(input("How much money do you want to send to {}\t{}".format(customer.customer_list["name"][index_transfer],
customer.customer_list["surname"][index_transfer])))
if transfer_money > customer.customer_list["balance"][index]:
input("You do not have enough money to transfer \n"
"enter to return menu")
break
elif transfer_money == customer.customer_list["balance"][index]:
selection = input("You are about to send all your money are you sure [y/n] ")
if selection == "Y" or selection == "y":
customer.customer_list["balance"][index_transfer] += transfer_money
customer.customer_list["balance"][index] -= transfer_money
wait(3)
print("Operation completed")
break
elif selection == "N" or selection == "n":
print("Operation cancelling...")
break
else:
while True:
print("Press valid button")
break
elif transfer_money < customer.customer_list["balance"][index]:
customer.customer_list["balance"][index_transfer] += transfer_money
customer.customer_list["balance"][index] -= transfer_money
wait(3)
print("Operation completed")
break
except ValueError:
print("Please write integer value")
break
else:
print("You can not send money on your own")
else:
print("Could not find user")
break
else:
while True:
print("Invalid choice")
break
else:
while True:
if input("Wrong password or username \n"
"to main menu press enter") == "":
break
elif selection == "2":
while True:
flag = customer.create_customers(input("Name:"), input("Surname:"), input("Primary conditions for password validation: \n"
"1.Minimum 8 characters. \n"
"2.The alphabets must be between [a-z] \n"
"3.At least one alphabet should be of Upper Case [A-Z]\n"
"4.At least 1 number or digit between [0-9]. \n"
"5.At least 1 character from [ _ or - or ! or @ ]."))
if flag == 0:
print("Your account is creating")
wait(3)
print("Your account has been created")
customer.add_customer()
input("-----------------------------\n"
"To continue press enter")
break
while True:
if flag == -1:
break
elif selection == "3":
while True:
print("Welcome to management part")
selection = input("--------------------------\n"
"Make a selection \n"
"[1] Show the customer information\n"
"[2] Remove customers\n"
"[Q] to return main menu")
if selection == "1":
print("Name:{}\n"
"Surname:{}\n"
"Password:{}\n"
"Identity:{}\n"
"Balance:{}".format(customer.customer_list["name"],
customer.customer_list["surname"],
customer.customer_list["password"],
customer.customer_list["identity"],
customer.customer_list["balance"]))
elif selection == "2":
if len(customer.customer_list["name"]) == 0:
print("There are no customers")
enter = input("Press enter to return main menu\n")
if enter == "":
break
else:
flag = customer.is_there_customer(input("Name"), input("Surname"))
if flag == 0:
while True:
enter = input("Press enter to return main menu\n"
"--------------------------------")
if enter == "":
break
elif enter != "":
while True:
print("Please press valid button\n"
"Press enter to return main menu\n")
break
else:
print("The user can not found")
elif selection == "q" or selection == "Q":
break
else:
while True:
print("Press valid button")
break
else:
while True:
print("Please make a valid selection")
print("-----------------------------\n"
"To continue press enter")
input()
break
main()