-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
271 lines (249 loc) · 11.3 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
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
import json
import subprocess as sp
from time import sleep, time
with open('accounts.json') as f:
data = json.load(f)
def clear():
tmp = sp.call('cls', shell=True)
def new_user():
# Taking the new users name
new_data = {}
name = ""
checker_name = 0
while checker_name != 1:
first_name = input("Enter your First name: ")
middile_name = input("Enter your Middle name(Leave empty if none): ")
last_name = input("Enter your Last name: ")
if len(middile_name) == 0:
name = first_name+" "+last_name
else:
name = first_name+" "+middile_name+" "+last_name
name_checker = list(name)
for i in range(len(name_checker)):
asci_val = ord(name_checker[i])
if (asci_val <= 90 and asci_val >= 65) or (asci_val <= 122 and asci_val >= 97) or asci_val == 32:
checker_name = 1
else:
checker_name = 0
print("Invalid Input!! Enter Your name again: \n")
break
if checker_name == 1:
new_data['name'] = name
print(f"Welcome {name} to the Bank of TBC\n")
# taking the new users pin
checker_PIN = 0
account_PIN_enter = 0000
while checker_PIN != 1:
account_PIN_enter = int(input("Enter you 4 digit PIN: "))
account_PIN_checker = int(input("Re-enter you 4 digit PIN: "))
if account_PIN_enter == account_PIN_checker:
if account_PIN_enter > 999 and account_PIN_enter < 10000:
checker_PIN = 1
else:
checker_PIN = 0
print(
"PIN must be 4 Digit and cannot start with 0! Enter the Pin again: \n")
else:
checker_PIN = 0
print("Entered PIN does not match! Enter the Pin again: \n")
if checker_PIN == 1:
new_data['PIN'] = account_PIN_enter
# creating the acc number
account_number = len(data['people'])+1
new_data['acc_number'] = account_number
print(f"\nYour account number is: {account_number}")
# setting the default accont balance at 0
account_balance = 0
new_data['acc_balance'] = account_balance
print(f"\nYour account balance is: {account_balance}")
sleep(5)
# entering the data to the json file
data['people'].append(new_data)
with open('accounts.json', 'w') as f:
json.dump(data, f, indent=2)
def existing_user():
if len(data['people']) > 0:
num = 0
while True:
check_acc_num = int(input("Please enter your Account Number: "))
for i in range(len(data['people'])):
if check_acc_num == data['people'][i]['acc_number']:
num = i
break
if i == len(data['people']) and check_acc_num != data['people'][i-1]['acc_number']:
print("Invalid Account Number!!")
if check_acc_num == data['people'][num]['acc_number']:
break
accountdetails = data['people'][num]
name = accountdetails['name']
print(f"Welcome {name}\n")
while True:
check_PIN_1 = int(input("Enter Your PIN : "))
if check_PIN_1 == accountdetails['PIN']:
check_PIN_2 = int(input("Re-enter Your PIN : "))
if check_PIN_2 == check_PIN_1:
print("PIN is correct!")
break
else:
print("The PINs do not match!")
else:
print("Incorrect PIN!")
while True:
clear()
print(f"Welcome {name} to the Bank of TBC\n")
choice2 = int(input(
"\n1. View Balance\n2. Deposit\n3. Withdraw\n4. Transfer\n5. Profile\n6. Logout\n"))
if choice2 == 1:
clear()
balance = accountdetails['acc_balance']
print(f"Your Account Balance is: {balance}")
sleep(4)
elif choice2 == 2:
clear()
enter_amount = int(
input("Enter the amount you want to deposit: "))
new_balance = accountdetails['acc_balance']+enter_amount
data['people'][num]['acc_balance'] = new_balance
with open('accounts.json', 'w') as f:
json.dump(data, f, indent=2)
print(
f"Amount of Rs. {enter_amount} has been credited to your account!")
print(f"Your Balance is: {new_balance}")
sleep(3)
elif choice2 == 3:
while True:
clear()
enter_amount = int(
input("Enter the amount you want to withdraw: "))
if enter_amount > accountdetails['acc_balance']:
print("You do not have this ammount of money!")
else:
new_balance = accountdetails['acc_balance'] - \
enter_amount
data['people'][num]['acc_balance'] = new_balance
with open('accounts.json', 'w') as f:
json.dump(data, f, indent=2)
print(
f"Amount of Rs. {enter_amount} has been debited from your account!")
print(f"Your Balance is: {new_balance}")
sleep(3)
break
elif choice2 == 4:
new_num = 0
while True:
clear()
enter_acc_num = int(
input("Enter the Account number of the account you want to transfer: "))
if enter_amount > accountdetails['acc_balance']:
print("You do not have this ammount of money!")
for i in range(len(data['people'])):
if enter_acc_num == data['people'][i]['acc_number']:
new_num = i
break
if i == len(data['people']) and enter_acc_num != data['people'][i-1]['acc_number']:
print("Invalid Account Number!!")
if enter_acc_num == data['people'][new_num]['acc_number']:
newaccountdetails = data['people'][new_num]
new_name = newaccountdetails['name']
check_if_name_ok = input(
f"Do you want to transfer to {new_name}? (Y/N)")
while True:
if check_if_name_ok == 'Y' or check_if_name_ok == 'y':
amount = int(
input("Enter the amount that you want to transfer: "))
other_person_new_balance = newaccountdetails['acc_balance']+amount
own_new_balance = accountdetails['acc_balance']-amount
data['people'][num]['acc_balance'] = own_new_balance
data['people'][new_num]['acc_balance'] = other_person_new_balance
with open('accounts.json', 'w') as f:
json.dump(data, f, indent=2)
print("Transfer Complete")
sleep(3)
break
elif check_if_name_ok == 'N' or check_if_name_ok == 'n':
break
else:
print("Invalid Input Enter 'Y' or 'N'")
break
elif choice2 == 6:
break
elif choice2 == 5:
while True:
clear()
name = accountdetails['name']
pin = accountdetails['PIN']
balance = accountdetails['acc_balance']
acc_num = accountdetails['acc_number']
print(
f"Account Holder Name: {name}\nAccount Number: {acc_num}\nPIN: {pin}\nAccount Balance: {balance}\n")
choice3 = int(
input("\n\n1. Change PIN\n2. Go back to Account Menu\n3. Delete Account\n"))
if choice3 == 2:
break
elif choice3 == 1:
while True:
clear()
curr_PIN = int(input("Enter your Current PIN: "))
if curr_PIN == accountdetails['PIN']:
new_PIN = int(input("Enter your New PIN: "))
if new_PIN > 999 and new_PIN < 10000:
data['people'][num]['PIN'] = new_PIN
with open('accounts.json', 'w') as f:
json.dump(data, f, indent=2)
print(
f"PIN changed Sucessfully!\nYour new PIN is: {new_PIN}")
sleep(3)
break
else:
print(
"PIN must be 4 Digit and cannot start with 0!\n")
else:
print("Incorrect PIN!")
elif choice3 == 3:
confirm = input(
"Are you sure you want to delete your account!!(Y/N)? ")
if confirm == 'Y' or confirm == 'y':
while True:
check_PIN_1 = int(input("Enter Your PIN : "))
if check_PIN_1 == accountdetails['PIN']:
check_PIN_2 = int(
input("Re-enter Your PIN : "))
if check_PIN_2 == check_PIN_1:
data['people'].pop(num)
with open('accounts.json', 'w') as f:
json.dump(data, f, indent=2)
print(
"Account Sucessfully Deleted! and your money is gone forever!!")
sleep(3)
break
else:
print("The PINs do not match!")
else:
print("Incorrect PIN!")
break
else:
print("There are no accounts in this bank!")
def about():
print('''\n==========ABOUT US==========
This project has been created by Aman Khadka.
It is a basic Python Project for my 1st Semester.''')
def developer_mode():
print(data)
sleep(10)
# main
while True:
print("Welcome to the Bank of TBC\n")
choice1 = int(input("1. Sign up\n2. Login\n3. About\n4. Exit\n"))
if choice1 == 1:
clear()
new_user()
elif choice1 == 2:
clear()
existing_user()
elif choice1 == 3:
about()
elif choice1 == 5:
clear()
developer_mode()
elif choice1 == 4:
break