Question
Instruction to be written in python. The missing code is specified ------------missing code----------------- and that is the code i need. Please answer 1-8, thank you
Instruction to be written in python. The missing code is specified ------------missing code----------------- and that is the code i need. Please answer 1-8, thank you
1.
import nose.tools as tools
CODE: def import_and_create_dictionary(filename):
d = {}
--------------------------missing code-------------------
bank = import_and_create_dictionary("bank.txt")
tools.assert_false(len(bank) == 0) tools.assert_almost_equal(115.5, bank.get("Brandon"))
tools.assert_almost_equal(128.87, bank.get("James")) tools.assert_is_none(bank.get("Joel")) tools.assert_is_none(bank.get("Luke")) tools.assert_almost_equal(bank.get("Sarah"), 827.43)
2.
CODE: def signup(user_accounts, log_in, username, password):
---------------------------missing code-------------------
3
CODE: def import_and_create_accounts(filename):
user_accounts = {} log_in = {}
---------------------------missing code-------------------
user_accounts, log_in = import_and_create_accounts("user.txt")
tools.assert_false(len(user_accounts) == 0) tools.assert_false(len(log_in) == 0) tools.assert_equal(user_accounts.get("Brandon"),"brandon123ABC") tools.assert_equal(user_accounts.get("Jack"),"jack123POU") tools.assert_is_none(user_accounts.get("Jennie")) tools.assert_false(log_in["Sarah"])
bank = import_and_create_dictionary("bank.txt") user_accounts, log_in = import_and_create_accounts("user.txt")
tools.assert_false(signup(user_accounts,log_in,"Brandon","123abcABCD"))
tools.assert_false(signup(user_accounts,log_in,"BrandonK","123ABCD")) tools.assert_false(signup(user_accounts,log_in,"BrandonK","1234ABCD")) tools.assert_false(signup(user_accounts,log_in,"BrandonK","abcdABCD")) tools.assert_false(signup(user_accounts,log_in,"BrandonK","1234abcd"))
tools.assert_false(signup(user_accounts,log_in,"123abcABCD","123abcABCD"))
tools.assert_true(signup(user_accounts,log_in,"BrandonK","123aABCD")) tools.assert_false(signup(user_accounts,log_in,"BrandonK","123aABCD")) tools.assert_true("BrandonK" in user_accounts) tools.assert_equal("123aABCD",user_accounts["BrandonK"]) tools.assert_false(log_in["BrandonK"])
4
.
CODE: def login(user_accounts, log_in, username, password):
---------------------------missing code-------------------
bank = import_and_create_dictionary("bank.txt") user_accounts, log_in = import_and_create_accounts("user.txt")
tools.assert_false(login(user_accounts, log_in,"Brandon","123abcAB")) tools.assert_true(login(user_accounts, log_in,"Brandon","brandon123ABC")) tools.assert_false(login(user_accounts, log_in,"BrandonK","123abcABC"))
5.
CODE: def update(bank, log_in, username, amount):
---------------------------missing code-------------------
bank = import_and_create_dictionary("bank.txt") user_accounts, log_in = import_and_create_accounts("user.txt")
tools.assert_false(update(bank,log_in,"Jack",100)) login(user_accounts, log_in, "Brandon", "brandon123ABC") tools.assert_false(update(bank,log_in,"Brandon",-400)) tools.assert_true(update(bank,log_in,"Brandon",100)) tools.assert_almost_equal(bank.get("Brandon"),215.5)
signup(user_accounts, log_in, "BrandonK", "123aABCD") tools.assert_is_none(bank.get("BrandonK")) login(user_accounts,log_in,"BrandonK","123aABCD") tools.assert_true(update(bank,log_in,"BrandonK",100)) tools.assert_almost_equal(bank.get("BrandonK"),100)
6
CODE: def transfer(bank, log_in, userA, userB, amount):
---------------------------missing code------------------
bank = import_and_create_dictionary("bank.txt") user_accounts, log_in = import_and_create_accounts("user.txt")
tools.assert_false(transfer(bank,log_in,"BrandonK","Jack",100)) tools.assert_false(transfer(bank,log_in,"Brandon","JackC",100)) tools.assert_false(transfer(bank,log_in,"Brandon","Jack",100))
login(user_accounts,log_in,"Brandon","brandon123ABC") tools.assert_false(transfer(bank,log_in,"Brandon","Jack",200)) tools.assert_true(transfer(bank,log_in,"Brandon","Jack",10)) tools.assert_almost_equal(bank.get("Brandon"),105.5) tools.assert_almost_equal(bank.get("Jack"),55)
signup(user_accounts,log_in,"BrandonK","123aABCD") tools.assert_is_none(bank.get("BrandonK")) login(user_accounts,log_in,"BrandonK","123aABCD") tools.assert_true(transfer(bank,log_in,"Brandon","BrandonK",10)) tools.assert_almost_equal(bank.get("Brandon"),95.5) tools.assert_almost_equal(bank.get("BrandonK"),10)
7.
CODE: def change_password(user_accounts, log_in, username, old_password, new_password):
---------------------------missing code-------------------
bank = import_and_create_dictionary("bank.txt") user_accounts, log_in = import_and_create_accounts("user.txt")
tools.assert_false(change_password(user_accounts,log_in,"BrandonK","123abcABC","123abcABCD")) tools.assert_false(change_password(user_accounts,log_in,"Brandon","brandon123ABC","123abcABCD"))
login(user_accounts,log_in,"Brandon","brandon123ABC") tools.assert_false(change_password(user_accounts,log_in,"Brandon","123abcABCD","123abcABCDE"))
tools.assert_false(change_password(user_accounts,log_in,"Brandon","brandon123ABC","brandon123ABC"))
tools.assert_false(change_password(user_accounts,log_in,"Brandon","brandon123ABC","123ABCD"))
tools.assert_true(change_password(user_accounts,log_in,"Brandon","brandon123ABC","123abcABCD")) tools.assert_equal("123abcABCD",user_accounts["Brandon"])
8.
CODE: def_delete_account(user_accounts, log_in, bank, username, password):
---------------------------missing code-------------------
bank = import_and_create_dictionary("bank.txt") user_accounts, log_in = import_and_create_accounts("user.txt")
tools.assert_false(delete_account(user_accounts,log_in,bank,"BrandonK","123abcABC")) tools.assert_false(delete_account(user_accounts,log_in,bank,"Brandon","123abcABDC")) tools.assert_false(delete_account(user_accounts,log_in,bank,"Brandon","brandon123ABC")) login(user_accounts,log_in,"Brandon","brandon123ABC")
tools.assert_true(delete_account(user_accounts,log_in,bank,"Brandon","brandon123ABC")) tools.assert_is_none(user_accounts.get("Brandon")) tools.assert_is_none(log_in.get("Brandon")) tools.assert_is_none(bank.get("Brandon"))
9. def main(): ''' The main function is a skeleton for you to test if your overall programming is working. Note we will not test your main function. It is only for you to run and interact with your program. '''
bank = import_and_create_dictionary("bank.txt") user_accounts, log_in = import_and_create_accounts("user.txt")
while True: # for debugging print('bank:', bank) print('user_accounts:', user_accounts) print('log_in:', log_in) print('') #
option = input("What do you want to do? Please enter a numerical option below. " "1. login " "2. signup " "3. change password " "4. delete account " "5. update amount " "6. make a transfer " "7. exit ") if option == "1": username = input("Please input the username ") password = input("Please input the password ")
# add code to login login(user_accounts, log_in, username, password); elif option == "2": username = input("Please input the username ") password = input("Please input the password ")
# add code to signup signup(user_accounts, log_in, username, password) elif option == "3": username = input("Please input the username ") old_password = input("Please input the old password ") new_password = input("Please input the new password ")
# add code to change password change_password(user_accounts, log_in, username, old_password, new_password) elif option == "4": username = input("Please input the username ") password = input("Please input the password ")
# add code to delete account delete_account(user_accounts, log_in, bank, username, password) elif option == "5": username = input("Please input the username ") amount = input("Please input the amount ") try: amount = float(amount)
# add code to update amount update(bank, log_in, username, amount) except: print("The amount is invalid. Please reenter the option ")
elif option == "6": userA = input("Please input the user who will be deducted ") userB = input("Please input the user who will be added ") amount = input("Please input the amount ") try: amount = float(amount)
# add code to transfer amount transfer(bank, log_in, userA, userB, amount) except: print("The amount is invalid. Please re-enter the option. ") elif option == "7": break; else: print("The option is not valid. Please re-enter the option. ")
#This will automatically run the main function in your program #Don't change this if __name__ == '__main__': main()
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 user's bank account. You'll implement functions related to File 1/0 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. 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. 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_ac 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. The given argument is the fi This function is used to create an user accounts dictionary and another login dictionary. 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. 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. count with the given amount. iven 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 undated. 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 users, 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. users 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 users can be absent from bank. No user can have a negative balance. Each must have a positive or zero balance 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. Deletes the user from the user_accounts. If the following requirements are met, delete the user from user_accounts and return True. - The user exists in user_accounts and the password is correct. Otherwise, return False For example: - Calling delete_account (user_accounts, log_in, bank, "BrandonK", "123abcABC") will return false - Calling delete_account (user_accounts, log_in, bank, "Brandon", "123 abCABDC") will return false - If you first log "Brandon" in, calling delete_account (user_accounts, log_in, bank, "Brandon", "brandon123ABC") will return True 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 user's bank account. You'll implement functions related to File 1/0 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. 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. 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_ac 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. The given argument is the fi This function is used to create an user accounts dictionary and another login dictionary. 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. 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. count with the given amount. iven 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 undated. 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 users, 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. users 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 users can be absent from bank. No user can have a negative balance. Each must have a positive or zero balance 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. Deletes the user from the user_accounts. If the following requirements are met, delete the user from user_accounts and return True. - The user exists in user_accounts and the password is correct. Otherwise, return False For example: - Calling delete_account (user_accounts, log_in, bank, "BrandonK", "123abcABC") will return false - Calling delete_account (user_accounts, log_in, bank, "Brandon", "123 abCABDC") will return false - If you first log "Brandon" in, calling delete_account (user_accounts, log_in, bank, "Brandon", "brandon123ABC") will return True
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