-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATM_mockup_app.py
212 lines (164 loc) · 7.3 KB
/
ATM_mockup_app.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
import random
import datetime
import time
database = {}
def init():
print("WELCOME TO BANK ZURI\n")
start()
def start():
print("What would you like to do?\nCreate a new account or login to existing account?")
options = input(f"Select 1 to create an account\n"
f"Select 2 to login\n"
f"Select 3 to exit application\n"
f"Enter option here: ")
if options.isdigit():
if int(options) == 1:
createAccount()
elif int(options) == 2:
logIn()
elif int(options) == 3:
exit
else:
print("Error!!! Invalid Selection!\n")
start()
else:
print("Error!!! Invalid Selection!\n")
start()
###login function
def logIn():
print("\nLogin to your account")
print("=====ENTER YOUR LOGIN DETAILS HERE=====")
userAccount = input("Enter your account number: ")
userPass = input("Enter your password: ")
###Login validation loop
if userAccount.isdigit():
UserAccount = int(userAccount)
if UserAccount in database.keys():
for key, value in database.items():
if UserAccount == key:
if userPass == value[3] in database[key]:
print("Login Successful!\n")
timeStamp = datetime.datetime.now().timestamp()
logInTime = time.ctime(timeStamp)
print(f"Welcome {value[1]} {value[2]}\n{logInTime}")
print("\n")
bankOperations(UserAccount)
else:
print("The account number and/or password entered is incorrect\n")
logIn()
elif UserAccount not in database.keys() and len(userAccount) != 10:
print("The account number and/or password entered is incorrect\n")
logIn()
else:
print("The account number entered does not exist\n")
start()
else:
print("Error!!! Account number must contain only digits\n")
logIn()
def createAccount():
print("\nCreate an account.")
print("*****REGISTER HERE*****")
###entering account info and loops for validatiing each input
firstName = input("What is your First Name?: ")
while len(firstName) == 0 or firstName.isspace() == True or firstName.isalpha() == False:
print('Error! First name cannot be empty or contain digits or spaces\n')
firstName = input("What is your First Name?: ")
lastName = input("What is your Last Name?: ")
while len(lastName) == 0 or lastName.isspace() == True or lastName.isalpha() == False:
print('Error! Last name cannot be empty or contain digits or spaces\n')
lastName = input("What is your Last Name?: ")
email = input("Enter your email address?: ")
while len(email) == 0 or email.isspace() == True:
print('Error! email cannot be empty\n')
email = input("Enter your email address?: ")
print(f"Create your unique password\n"
f"#Hint: password should be at least 8 characters, alphanumeric and must contain at least one lower and one uppercase letter\n")
###Password validation loop
validPassword = False
while validPassword == False:
password = input("Enter password here: ")
if len(password) >= 8:
isalphanum = not password.isdigit() and not password.isalpha()
if isalphanum == True:
validChar = not password.isupper() and not password.islower()
if validChar == True:
validPassword = True
break
print("Invalid password combination, please see hint above")
###generates account number and stores account details in database
accountNumber = generateAccountNumber()
print("\nYour account has been successfully created.")
print(f"Your account number is {accountNumber}. Please copy and store it safely\n")
database[accountNumber] = [email, firstName, lastName, password, 0]
logIn()
###banking transaction function
def bankOperations(account):
print("How can we help you today?")
print('The available options are: \n')
print('1. Cash Deposit\n')
print('2. Withdrawal\n')
print('3. Check Balance\n')
print('4. Complaints\n')
options = [1, 2, 3, 4]
select = input('Please select an option...: ')
###validates user input
if select.isdigit() == False:
print('ERROR! Invalid option selected, please try again\n')
bankOperations(account)
elif(int(select) > 0 and int(select) <= len(options)):
optionChoosen = int(select)
if optionChoosen == 1:
cashDeposit = int(input('How much would you like to deposit?: '))
updateBalance(account, cashDeposit, optionChoosen)
redoOperation(account)
elif optionChoosen == 2:
cashWithdrawn = int(input('How much would you like to withdraw?: '))
updateBalance(account, cashWithdrawn, optionChoosen)
redoOperation(account)
elif optionChoosen == 3:
balance = 0
updateBalance(account, balance, optionChoosen)
redoOperation(account)
else:
print('What issue will you like to report?')
complaint = input('Please enter your complaint here: ')
print('Your complaint has been forwarded to our customer care agents. We will get back to you shortly.')
print('Thank you for contacting us.\n')
redoOperation(account)
else:
print('ERROR! Invalid option selected, please try again\n')
bankOperations(account)
###updates balance per bank transaction for each customer
def updateBalance(acct_number, amount, opt):
for key, value in database.items():
if key == acct_number:
if value[4] in database[key] and opt == 1:
value[4] += amount
print('Deposit successful!')
print(f'Your current balance is: ${value[4]}\n')
elif value[4] in database[key] and opt == 2:
if amount <= value[4]:
value[4] -= amount
print(f'Take your cash: ${amount}\n')
print(f'Your current balance is: ${value[4]}\n')
else:
print(f"Sorry, your account balance is insufficient for this transaction. Please deposit funds\n"
f'Your current balance is: ${value[4]}\n')
elif value[4] in database[key] and opt == 3:
value[4] += amount
print(f'{value[1]}, your current balance is: ${value[4]}\n')
def redoOperation(acct):
other = int(input('Enter 1 to perform another operation or 2 to logout: \n'))
if other == 1:
bankOperations(acct)
elif other == 2:
logOut()
else:
print("Invalid selection!")
redoOperation(acct)
def logOut():
init()
def generateAccountNumber():
return random.randint(1111111111, 9999999999)
##### INITIALIZED BANKING SYSTEM #####
init()