-
Notifications
You must be signed in to change notification settings - Fork 49
/
Bank_Management_System.py
206 lines (178 loc) · 7.73 KB
/
Bank_Management_System.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
class Bank:
def __init__(self):
self.client_details_list = []
self.loggedin = False
self.cash = 100
self.TranferCash = False
def register(self, name, ph, password):
cash = self.cash
contitions = True
if len(str(ph)) > 10 or len(str(ph)) < 10:
print("Invalid Phone number ! please enter 10 digit number")
contitions = False
if len(password) < 5 or len(password) > 18:
print("Enter password greater than 5 and less than 18 character")
contitions = False
if contitions == 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")
def add_cash(self, amount):
if amount > 0:
self.cash += amount
with open(f"{name}.txt", "r") as f:
details = f.read()
self.client_details_list = details.split("\n")
with open(f"{name}.txt", "w") as f:
f.write(details.replace(
str(self.client_details_list[3]), str(self.cash)))
print("Amount added successfully")
else:
print("Enter correct value of amount")
def Tranfer_cash(self, amount, name, ph):
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.TranferCash = True
if self.TranferCash == True:
total_cash = int(self.client_details_list[3]) + amount
left_cash = self.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.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("Balacne left =", left_cash)
def password_change(self, password):
if len(password) < 5 or len(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_change(self, ph):
if len(str(ph)) > 10 or len(str(ph)) < 10:
print("Invalid Phone number ! please enter 10 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("Welcome to my Bank")
print("1.Login")
print("2.Creata 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 Balcane")
print("3.Tranfer amount")
print("4.Edit profile")
print("5.Logout")
login_user = int(input())
if login_user == 1:
print("Balance =", Bank_object.cash)
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("Balacne =", Bank_object.cash)
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.cash)
amount = int(input("Enter amount: "))
if amount >= 0 and amount <= Bank_object.cash:
name = input("Enter person name: ")
ph = input("Enter person phone number: ")
Bank_object.Tranfer_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.cash:
print("Not enough balance")
elif login_user == 4:
print("1.Password change")
print("2.Phone Number change")
edit_profile = int(input())
if edit_profile == 1:
new_passwrod = input("Enter new Password: ")
Bank_object.password_change(new_passwrod)
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_change(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
if 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)