This Study Resource Was
This Study Resource Was
def validate(username,password):
l, u, d = 0, 0, 0
if (len(password) >= 8):
for i in password:
# counting digits
if (i.isdigit()):
d+=1
m
result = "The username & password cannot be the same"
er as
else:
co
result = "Fail!!\n"+"- The password must be at least 8 characters. \n"+
eH w
"- The password must contain at least one lowercase character.\n "+"- The
password must contain at least one uppercase character.\n "+"- The password must
o.
contain at least one number.\n " rs e
return result
ou urc
def signup(user_accounts, bank, log_in, username, password):
'''
o
If both username and password meet the requirements, updates the username
v i y re
If the username and password fail to meet any one of the following
requirements, returns error message.
ed d
'''
Th
else:
return result
This study source was downloaded by 100000823114299 from CourseHero.com on 08-11-2021 08:00:54 GMT -05:00
https://www.coursehero.com/file/84274580/bank-managementpy/
def login(user_accounts, log_in, username, password):
'''
This function allows users to log in with their username and password.
The users_accounts stores the usernames and passwords.
If the username does not exist or the password is incorrect, return error
message.
Otherwise, return success message.
'''
if username in user_accounts:
#check password
if user_accounts[username] == password:
result = "log in success"
# update status
log_in[username] = True
else:
result = "Invalid password"
else:
result = "Not found account with username {}".format(username)
return result
m
er as
def update(bank, log_in, username, amount):
co
'''
eH w
In this function, you will try to update the given user's bank account with
the given amount.
o.
The amount is an integer, and can either be positive or negative.
rs e
ou urc
To update the user's account with the amount, the following requirements
must be met:
- The user exists in log_in and his/her status is True, meaning, the user is
logged in.
o
aC s
- The given amount can not result in a negative balance in the bank account.
'''
# check logged in
if log_in[username]:
ed d
if amount < 0:
ar stu
else:
Th
# bank[username] = float(amount)
return "Not found account"
else:
return "Not log in"
- Deduct the amount from userA and add it to userB, which makes a transfer.
- Consider some following cases:
- userA must be in accounts and his/her log-in status must be True.
- userB must be in log_in, regardless of log-in status.
This study source was downloaded by 100000823114299 from CourseHero.com on 08-11-2021 08:00:54 GMT -05:00
https://www.coursehero.com/file/84274580/bank-managementpy/
- No user can have a negative amount. He/she must have a positive or zero
amount.
try:
if log_in[userA]:
#ckeck amount
if amount <= bank[userA]:
bank[userA]-= amount
m
if userB in bank:
er as
bank[userB]+= amount
co
return "transfer success"
eH w
else:
return "Not fount recipient"
o.
else: rs e
return "Not enough amount"
ou urc
else:
return "user not log in"
except:
o
If all of the following requirements are met, change the password and return
True. Otherwise, return error message.
- The username exists in the user_accounts.
- The old_password is the user's current password.
- The new_password should be different from the old one.
sh is
This will also come in handy when writing the signup() function.
'''
This study source was downloaded by 100000823114299 from CourseHero.com on 08-11-2021 08:00:54 GMT -05:00
https://www.coursehero.com/file/84274580/bank-managementpy/
return "Not found account with username {} or user not log
in".format(username)
def delete_account(user_accounts, log_in, bank, username, password):
'''
Deletes the user from the user_accounts.
If the following requirements are met, delete the user from user_accounts
and return success message. Otherwise, return error message.
- The user exists in user_accounts and the password is correct.
'''
try:
if user_accounts[username] == password:
if log_in[username]:
# delete account
del user_accounts[username]
del log_in[username]
del bank[username]
return "delete account success"
else:
return "user not log in"
else:
return "Invalid username or password"
m
except:
er as
return "Not found account with username : {}".format(username)
co
eH w
def main():
pointer = True
o.
while pointer: rs e
# for debugging
ou urc
print("############################ ***Available bank account**
############################")
print('Available bank account:')
for key in bank:
o
print("username: ",key)
aC s
v i y re
print("################################################################")
print('')
#
below.\n"
ar stu
"1. login\n"
"2. signup\n"
"3. change password\n"
"4. delete account\n"
"5. deposit\n"
sh is
"7. exit\n")
if option == "1":
username = input("Please input the username\n")
password = input("Please input the password\n")
print("################################################################")
continue_flag = True
while continue_flag:
pt = input("Continuous? yes or no\n")
if pt == "yes":
pointer = True
This study source was downloaded by 100000823114299 from CourseHero.com on 08-11-2021 08:00:54 GMT -05:00
https://www.coursehero.com/file/84274580/bank-managementpy/
continue_flag = False
elif pt == "no":
pointer = False
continue_flag = False
else:
print("The option is not valid. Please re-enter the
option.\n")
elif option == "2":
username = input("Please input the username\n")
password = input("Please input the password\n")
print("################################################################")
continue_flag = True
while continue_flag:
pt = input("Continuous? yes or no\n")
if pt == "yes":
m
pointer = True
er as
continue_flag = False
co
elif pt == "no":
eH w
pointer = False
continue_flag = False
o.
else: rs e
print("The option is not valid. Please re-enter the
ou urc
option.\n")
elif option == "3":
username = input("Please input the username\n")
old_password = input("Please input the old password\n")
o
print(response)
ar stu
print("################################################################")
continue_flag = True
while continue_flag:
pt = input("Continuous? yes or no\n")
sh is
if pt == "yes":
Th
pointer = True
continue_flag = False
elif pt == "no":
pointer = False
continue_flag = False
else:
print("The option is not valid. Please re-enter the
option.\n")
pointer = False
elif option == "4":
username = input("Please input the username\n")
password = input("Please input the password\n")
This study source was downloaded by 100000823114299 from CourseHero.com on 08-11-2021 08:00:54 GMT -05:00
https://www.coursehero.com/file/84274580/bank-managementpy/
############################")
print(response)
print("################################################################")
continue_flag = True
while continue_flag:
pt = input("Continuous? yes or no\n")
if pt == "yes":
pointer = True
continue_flag = False
elif pt == "no":
pointer = False
continue_flag = False
else:
print("The option is not valid. Please re-enter the
option.\n")
elif option == "5":
username = input("Please input the username\n")
amount = input("Please input the amount\n")
try:
amount = float(amount)
# add code to update amount
m
response = update(bank, log_in, username, amount)
er as
print("############################ ***Result**
co
############################")
eH w
print(response)
o.
print("################################################################")
rs e
continue_flag = True
ou urc
while continue_flag:
pt = input("Continuous? yes or no\n")
if pt == "yes":
pointer = True
o
continue_flag = False
aC s
elif pt == "no":
v i y re
pointer = False
else:
print("The option is not valid. Please re-enter the
option.\n")
except:
ed d
try:
Th
amount = float(amount)
# add code to transfer amount
response = transfer(bank, log_in, userA, userB, amount)
print("############################ ***Result**
############################")
print(response)
print("################################################################")
continue_flag = True
while continue_flag:
pt = input("Continuous? yes or no\n")
if pt == "yes":
pointer = True
continue_flag = False
elif pt == "no":
pointer = False
continue_flag = False
This study source was downloaded by 100000823114299 from CourseHero.com on 08-11-2021 08:00:54 GMT -05:00
https://www.coursehero.com/file/84274580/bank-managementpy/
else:
print("The option is not valid. Please re-enter the
option.\n")
except:
print("The amount is invalid. Please re-enter the option.\n")
elif option == "7":
break
else:
print("The option is not valid. Please re-enter the option.\n")
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
v i y re
ed d
ar stu
sh is
Th
This study source was downloaded by 100000823114299 from CourseHero.com on 08-11-2021 08:00:54 GMT -05:00
https://www.coursehero.com/file/84274580/bank-managementpy/
Powered by TCPDF (www.tcpdf.org)