Question
Python PLEASE NOTE THAT I NEED HELP IN THE SECTIONS WHERE IT SAYS YOUR CODE HERE In this assignment, you will implement an online banking
Python
PLEASE NOTE THAT I NEED HELP IN THE SECTIONS WHERE IT SAYS "YOUR CODE HERE"
In this assignment, you will implement an online banking system. Users can sign-up with the system, log in to the system, change their password, and delete their account. They can also update their bank account balance and transfer money to another users bank account.
Youll implement functions related to File I/O and dictionaries. The first two functions require you to import files and create dictionaries. User information will be imported from the users.txt file and account information will be imported from the bank.txt file. Take a look at the content in the different files. The remaining functions require you to use or modify the two dictionaries created from the files.
Each function has been defined for you, but without the code. See the docstring in each function for instructions on what the function is supposed to do and how to write the code. It should be clear enough. In some cases, we have provided hints to help you get started.
def import_and_create_dictionary(filename): ''' This function is used to create a bank dictionary. The given argument is the filename to load. Every line in the file will look like key: value Key is a user's name and value is an amount to update the user's bank account with. The value should be a number, however, it is possible that there is no value or that the value is an invalid number.
What you will do: - Try to make a dictionary from the contents of the file. - If the key doesn't exist, create a new key:value pair. - If the key does exist, increment its value with the amount. - You should also handle cases when the value is invalid. If so, ignore that line and don't update the dictionary. - Finally, return the dictionary.
Note: All of the users in the bank file are in the user account file.
1 - def import_and_create_dictionary(filename): -- this function was written by me
d = {}
with open(filename,"r") as file:
for line in file:
try:
(dictkey,dictval) = (line.split(':')[0],line.split(':')[1])
except IndexError as i:
continue
(dictkey,dictval) = (dictkey.strip(),dictval.strip())
fval = 0.0
try:
fval = float(dictval)
except ValueError as v:
continue
if dictkey in d.keys():
d[dictkey] += fval
else:
d[dictkey] = fval
return d
print(import_and_create_dictionary("bank.txt"))
2- def signup(user_accounts, log_in, username, password): -- don't know how to implement this one ''' This function allows users to sign up. If both username and password meet the requirements, updates the username and the corresponding password in the user_accounts, and returns True. If the username and password fail to meet any one of the following requirements, returns False. - The username already exists in the user_accounts. - The password must be at least 8 characters. - The password must contain at least one lowercase character. - The password must contain at least one uppercase character. - The password must contain at least one number. - The username & password cannot be the same. For example: - Calling signup(user_accounts, log_in, "Brandon", "123abcABCD") will return False - Calling signup(user_accounts, log_in, "BrandonK", "123ABCD") will return False - Calling signup(user_accounts, log_in, "BrandonK","abcdABCD") will return False - Calling signup(user_accounts, log_in, "BrandonK", "123aABCD") will return True. Then calling signup(user_accounts, log_in, "BrandonK", "123aABCD") again will return False. Hint: Think about defining and using a separate valid(password) function that checks the validity of a given password. This will also come in handy when writing the change_password() function. ''' # your code here
3- def import_and_create_accounts(filename): -- don't know how to implement this one ''' This function is used to create an user accounts dictionary and another login dictionary. The given argument is the filename to load. Every line in the file will look like username - password
If the username and password fulfills the requirement, add the username and password into the user accounts dictionary. To make sure that the password fulfills these requirements, be sure to use the signup function that you wrote above. For the login dictionary, the key is the username, and its value indicates whether the user is logged in, or not. Initially, all users are not logged in.
Finally, return the dictionaries.
Note: All of the users in the bank file are in the user account file. '''
user_accounts = {} log_in = {}
# write code here
return user_accounts,log_in
4 - def login(user_accounts, log_in, username, password): implemented, but not sure if correct ''' 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 False. Otherwise, return True.
For example: - Calling login(user_accounts, "Brandon", "123abcAB") will return False - Calling login(user_accounts, "Brandon", "brandon123ABC") will return True Note: If a user is already logged in, this should return False - a user cannot log in a second time once logged in '''
loggedin = [] flag="true" for lst in user_accounts: if(lst[0]==log_in and lst[1] == password): for log in loggedin: if(log ==log_in): print("A user cant login second time once logged in") flag="false" break else: flag="false" if(flag=="true"): loggedin.append(log_in) # adding user to loggedin list print("logged in succesfully") return True return False
5 - def update(bank, log_in, username, amount): didn't know how to implement ''' In this function, you will try to update the given user's bank account with the given amount. The amount is an integer, and can either be positive or negative.
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.
If the user doesn't exist in the bank, create the user. - The given amount can not result in a negative balance in the bank account.
return True if the user's account was updated.
For example: - Calling update(bank, log_in, "Brandon", 100) will return False, unless "Brandon" is first logged in. Then it will return True. - Calling update(bank, log_in, "Brandon", -200) will return False '''
# your code here
6 - def transfer(bank, log_in, userA, userB, amount): -- didn't know how to implement ''' In this function, you will try to make a transfer between two user accounts. The bank is a dictionary, where the key is the username and the value is the amount to transfer. Amount is always positive.
What you will do: - Deduct the amount from userA and add it to userB, which makes a transfer. - You should 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. userB can be absent in accounts. - No user can have a negative amount. He/she must have a positive or zero amount.
Return True if a transfer is made. If a user is invalid or the amount is invalid, return False. userA must be in bank and userB can be absent from bank. No user can have a negative balance. Each must have a positive or zero balance
For example: - Calling transfer(bank, log_in, "BrandonK", "Jack", 100) will return False - Calling transfer(bank, log_in, "Brandon", "JackC", 100) will return False - After logging "Brandon" in, calling transfer(bank, log_in, "Brandon", "Jack", 10) will return True - Calling transfer(bank, log_in, "Brandon", "Jack", 200) will return False Note that the arguments correspond as follows: o bank: The bank accounts dictionary o log_in: The user accounts dictionary o userA: The account from which the funds will be transferred o userB: The account to which the funds will be transferred o amount: The amount to transfer '''
# your code here
7- def change_password(user_accounts, log_in, username, old_password, new_password): didn't know how to implement ''' This function allows users to change their password. If all of the following requirements are met, change the password and return True. Otherwise, return False. - 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. - The new_password fulfills the requirement in signup. For example: - Calling change_password(user_accounts, log_in, "BrandonK", "123abcABC" ,"123abcABCD") will return False - Calling change_password(user_accounts, log_in, "Brandon", "123abcABCD", "123abcABCDE") will return False - Calling change_password(user_accounts, log_in, "Brandon", "brandon123ABC", "brandon123ABC") will return False - Calling change_password(user_accounts, log_in, "Brandon", "brandon123ABC", c"123abcABCD") will return True Hint: Think about defining and using a separate valid(password) function that checks the validity of a given password. This will also come in handy when writing the signup() function. '''
# your code here
8 - def delete_account(user_accounts, log_in, bank, username, password): didn't know how to implement ''' Deletes the user from the user_accounts. If the following requirements are met, delete the user from user_accounts and return True. Otherwise, return False. - The user exists in user_accounts and the password is correct.
For example: - Calling delete_account(user_accounts, log_in, bank, "BrandonK", "123abcABC") will return False - Calling delete_account(user_accounts, log_in, bank, "Brandon", "123abcABDC") will return False - If you first log "Brandon" in, calling delete_account(user_accounts, log_in, bank, "Brandon", "brandon123ABC") will return True '''
# your code her
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started