-
Notifications
You must be signed in to change notification settings - Fork 0
/
BankSys.py
228 lines (187 loc) · 8.98 KB
/
BankSys.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
class Bank:
def __init__(self):
self.client_details_list = []
self.loggedin = False
self.cash = 100
self.TransferCash = False
def register(self, name, ph, password):
cash = self.cash
condition = True
if len(str(ph)) < 10 or len(str(ph)) > 10:
print("Invalid phone number! Please enter 11 digit number")
condition = False
if len(password) < 5 or len(password) > 18:
print("Enter password greater than 5 and less than 18 character")
condition = False
if condition == True:
print("Account created successfully")
self.client_details_list = [name, ph, password, cash]
with open (f"{name}.txt", "w+") as f:
for details in self.client_details_list:
f.write(str(details)+"\n")
def login(self, name, ph, password):
with open(f"{name}.txt", "r") as f:
details = f.read()
self.client_details_list = details.split("\n")
if str(ph) in str(self.client_details_list):
if str(password) in str(self.client_details_list):
self.loggedin = True
if self.loggedin == True:
print(f"{name} logged in")
self.cash = int(self.client_details_list[3])
self.name = name
else:
print("Wrong details")
exit()
@property
def check_balance(self):
with open(f"{self.name}.txt", "r") as f:
details = f.read()
self.client_details_list = details.split("\n")
Balance = self.client_details_list[3]
return int(Balance)
def add_cash(self, amount):
if amount > 0:
cash = self.check_balance
cash += amount
with open(f"{self.name}.txt", "r") as f:
details = f.read()
self.client_details_list = details.split("\n")
with open(f"{self.name}.txt", "w") as f:
f.write(details.replace(str(self.client_details_list[3]),str(cash)))
print("Amount added successfully")
else:
print("Enter correct value of amount")
def Transfer_cash(self, amount, name, ph):
cash = self.check_balance
with open(f"{name}.txt", "r") as f:
details = f.read()
self.client_details_list = details.split("\n")
if str(ph) in self.client_details_list:
self.TransferCash = True
if self.TransferCash == True:
total_cash = int(self.client_details_list[3]) + amount
left_cash = cash - amount
with open(f"{name}.txt", "w") as f:
f.write(details.replace(str(self.client_details_list[3]),str(total_cash)))
with open(f"{self.name}.txt", "r") as f:
details_2 = f.read()
self.client_details_list = details_2.split("\n")
with open(f"{self.name}.txt", "w") as f:
f.write(details_2.replace(str(self.client_details_list[3]),str(left_cash)))
print("Amount Transfered Successfully to ", name,"-", ph)
print("Balance left = ",left_cash)
def password_change(self, password):
if len(str(password)) < 5 or len(str(password)) > 18:
print("Enter password greater than 5 and less than 18 character")
else:
with open(f"{self.name}.txt", "r") as f:
details = f.read()
self.client_details_list = details.split("\n")
with open(f"{self.name}.txt", "w") as f:
f.write(details.replace(str(self.client_details_list[2]),str(password)))
print("New password set up successfully")
def ph_chnage(self, ph):
if len(str(ph)) < 10 or len(str(ph)) > 10:
print("Invalid phone number! Please enter 11 digit number")
else:
with open(f"{self.name}.txt", "r") as f:
details = f.read()
self.client_details_list = details.split("\n")
with open(f"{self.name}.txt", "w") as f:
f.write(details.replace(str(self.client_details_list[1]),str(ph)))
print("New phone number set up successfully")
if __name__ == "__main__":
Bank_object = Bank()
print("Welcomw to my Bank")
print("1. Login")
print("2. Create a new Account")
user = int(input("Make Decision: "))
if user == 1:
print("Logging in......")
name = input("Enter Name: ")
ph = int(input("Enter Phone Number: "))
password = input("Enter Password: ")
Bank_object.login(name, ph, password)
while True:
if Bank_object.loggedin:
print("1. Add amount")
print("2. Check Balance")
print("3. Transfrt amount")
print("4. Edit Profile")
print("5. Logout")
login_user = int(input("--> "))
if login_user == 1:
print("Balance = ",Bank_object.check_balance)
amount = int(input("Enter amount: "))
Bank_object.add_cash(amount)
print("\n1. Back menu")
print("2. Logout")
choose = int(input("--> "))
if choose == 1:
continue
elif choose == 2:
break
elif login_user == 2:
print("Balance = ",Bank_object.check_balance)
print("\n1. Back menu")
print("2. Logout")
choose = int(input("--> "))
if choose == 1:
continue
elif choose == 2:
break
elif login_user == 3:
print("Balance = ",Bank_object.check_balance)
amount = int(input("Enter amount: "))
if amount > 0 and amount <= Bank_object.check_balance:
name = input("Enter Person name: ")
ph = input("Enter person phone number: ")
Bank_object.Transfer_cash(amount, name, ph)
print("\n1. Back menu")
print("2. Logout")
choose = int(input("--> "))
if choose == 1:
continue
elif choose == 2:
break
elif amount <= 0:
print("Enter please correct value of amount")
elif amount > Bank_object.check_balance:
print("Not enough balance")
elif login_user == 4:
print("1. Password change")
print("2. Phone No. change")
edit_profile = int(input("--> "))
if edit_profile == 1:
new_password = input("Enter new password: ")
Bank_object.password_change(new_password)
print("\n1. Back menu")
print("2. Logout")
choose = int(input("--> "))
if choose == 1:
continue
elif choose == 2:
break
elif edit_profile == 2:
new_ph = int(input("Enter new phone number: "))
Bank_object.ph_chnage(new_ph)
print("\n1. Back menu")
print("2. Logout")
choose = int(input("--> "))
if choose == 1:
continue
elif choose == 2:
break
elif login_user == 5:
break
else:
print("Wrong input")
elif user == 2:
print("Creating a new Account")
name = input("Enter Name: ")
ph = int(input("Enter Phone Number: "))
password = input("Enter Password: ")
Bank_object.register(name, ph, password)
else:
print("Wrong input")