Question: To answer in python. Fill in missing code.Instructions are in red. Youll implement functions related to File I/O and dictionaries. User information will be imported

To answer in python. Fill in missing code.Instructions are in red. Youll implement functions related to File I/O and 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.

To answer in python. Fill in missing code.Instructions are in red. Youll

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"])

implement functions related to File I/O and dictionaries. User information will be

CODE:

def login(user_accounts, log_in, username, password):

--------------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"))

The given argument is the fil This function is used to create an user accounts dictionary and another login dictionary. Svery line in the file will look like username - password [f 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. 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 in a second time once logged in a user cannot log

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!