-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
201 lines (152 loc) · 6.04 KB
/
Copy pathmain.py
File metadata and controls
201 lines (152 loc) · 6.04 KB
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
import json
import random
import string
from pathlib import Path
class Bank:
database = 'data.json'
data = []
try:
if Path(database).exists():
with open(database) as fs:
data = json.loads(fs.read())
else:
print("No such file exist ")
except Exception as err:
print(f"An exception occured as {err}")
@classmethod
def __update(cls):
with open(cls.database,'w') as fs:
fs.write(json.dumps(Bank.data))
@classmethod
def __accountgenerate(cls):
alpha = random.choices(string.ascii_letters,k=3)
num = random.choices(string.digits,k=3)
spchar = random.choices("!@#$%^&*",k=1)
id = alpha+num+spchar
random.shuffle(id)
return "".join(id)
def Createaccount(self):
info = {
"name": input("Enter your name: "),
"age": int(input("Enter Your age: ")),
"Email": input("Enter your Email: "),
"Pin": int(input("Enter Pin: ")),
"account":Bank.__accountgenerate(),
"balance":0
}
if info['age'] < 18 or len(str(info['Pin'])) !=4:
print("Sorry you can't create your account")
else:
print("Account has been created succesfully")
for i in info:
print(f"{i}:{info[i]}")
print("Please note down your account number")
Bank.data.append(info)
Bank.__update()
def depositmoney(self):
accnumber = input("Please Enter your Account number: ")
pin = int(input("Please Enter your pin Aswell: "))
userdata = [i for i in Bank.data if i['account'] == accnumber and i['Pin'] == pin]
if not userdata:
print("Sorry No data found")
else:
amount = int(input("How much you want to deposit: "))
if amount > 100000:
print("Sorry the amount is too much you can deposit upto 100000")
else:
userdata[0]['balance'] += amount
Bank.__update()
print("Amount deposited succesfully")
print(Bank.data)
def showdetails(self):
accnumber = input("please Enter your Account number: ")
pin = int(input("please Enter your pin Aswell "))
userdata = [i for i in Bank.data if i['account'] == accnumber and i['Pin'] == pin]
if not userdata:
print("No user found")
return
print("Your info:\n")
for i in userdata[0]:
print(f"{i}:{userdata[0][i]}")
def updatedetails(self):
accnumber = input("please Enter your Account number: ")
pin = int(input("please Enter your pin Aswell "))
userdata = [i for i in Bank.data if i['account'] == accnumber and i['Pin'] == pin]
if not userdata:
print("User not found! ")
else:
print("You can't change Age and Account number ")
print("Fill the details for change or leave it empty if no change ")
newdata = {
"name": input("please Enter your name or enter to skip :"),
"Email": input("Enter the email or enter to skip : "),
"Pin": input("enter new Pin or press enter to skip: ")
}
if newdata["name"] == "":
newdata["name"] = userdata[0]["name"]
if newdata["Email"] == "":
newdata["Email"] = userdata[0]["Email"]
if newdata["Pin"] == "":
newdata["Pin"] = userdata[0]["Pin"]
newdata['age'] = userdata[0]['age']
newdata['account'] = userdata[0]['account']
newdata['balance'] = userdata[0]['balance']
if type(newdata['Pin']) == str:
newdata['Pin'] = int(newdata["Pin"])
for i in newdata:
if newdata[i] == userdata[0][i]:
continue
else:
userdata[0][i] = newdata[i]
Bank.__update()
print("Details updated successfully")
def Delete(self):
accnumber = input("please Enter your Account number: ")
pin = int(input("please Enter your pin Aswell "))
userdata = [i for i in Bank.data if i['account'] == accnumber and i['Pin'] == pin]
if not userdata:
print("Sorrt no such data: ")
else:
check = input("press y if you actually want to delete ")
if check == 'n' or check =='N':
print("Bypassed")
else:
index = Bank.data.index(userdata[0])
Bank.data.pop(index)
print("Account Deleted SUccesfully ")
Bank.__update()
def withdrawmoney(self):
accnumber = input("Please Enter your Account number: ")
pin = int(input("Please Enter your pin Aswell: "))
userdata = [i for i in Bank.data if i['account'] == accnumber and i['Pin'] == pin]
if not userdata:
print("Sorry No data found")
else:
amount = int(input("Please Enter the Withdrawal amount : "))
if userdata[0]['balance'] < amount:
print("insufficient Balance")
else:
userdata[0]['balance'] -= amount
Bank.__update()
print("Amount withdrawn succesfully")
print(Bank.data)
user = Bank()
print("Press 1 for creating an account: ")
print("Press 2 for Depositing the money in the bank: ")
print("Press 3 for Withdrawing the money: ")
print("press 4 for details: ")
print("press 5 for updating the details ")
print("Press 6 for Deleting your account: ")
check = int(input("Enter your Response: "))
if check == 1:
user.Createaccount()
if check == 2:
user.depositmoney()
if check == 3:
user.withdrawmoney()
if check == 4:
user.showdetails()
if check == 5:
user.updatedetails()
if check == 6:
user.Delete()