2. Create a contacts module to meet the following requirements: i. Create a file named contacts.py. a. Define a class named Contacts. a. Define a member function named_init_ to meet the following requirements: a. Take a self as a positional parameter. b. Take a filename as a keyword parameter. c. Set a member variable equal to the filename. d. Set a member varialbe equal to an empty data dictionary. e. Open the filename and load the JSON decoded contents to the empty data dictionary. f. Cleanly manage the FileNotFoundError if the filename does not exist. b. Define a member function named add_contact to meet the following requirements: a. Take a self as a positional parameter. b. Take a id as a keyword parameter. c. Take a first_name as a keyword parameter. d. Take a last_name as a keyword parameter. e. If the id exists in the data dictionary, return the string error. f. Set the id:[first_name, last_name] key:value pair to the data dictionary. g. Sort the data dictionary in ascending order by last name, and then by first name, ignoring case. h. Write the contents of the data dictionary to the filename that was set to the member variable. i. Return the key:value pair that was added. c. Define a member function named modify_contact to meet the following requirements: a. Take a self as a positional parameter. b. Take a id as a keyword parameter. c. Take a first_name as a keyword parameter. d. Take a last_name as a keyword parameter. e. If the id does not exists in the dictionary, return the string error. f. Set the id:[first_name, last_name'] key:value pair to the contact dictionary. g. Sort the data dictionary in ascending order by last name, and then by first name, ignoring case. h. Write the contents of the data dictionary to the filename that was set to the member variable. i. Return the key:value pair that was modified. d. Define a member function named delete_contact to meet the following requirements: a. Take a self as a positional parameter. b. Take a id as a keyword parameter. c. If the id does not exists in the dictionary, return the string error. d. Remove the key:value pair with the key equal to id. e. Write the contents of the data dictionary to the filename that was set to the member variable. f. Return the key:value pair with the key equal to id. 3. Create a main driver program to meet the following requirements: i. Create a file named main.py. ii. Import the contacts module. iii. Instantiate a Contacts object with any default filename. iv. Implement a menu within a loop with following choices: a. Add contact b. Modify contact c. Delete contact d. Print contact list e. Set contact filename f. Exit the program v. Prompt the user for the menu choice. vi. Prompt the user for the information needed for the appropriate Contacts member function and call the function. vii. Print out appropriate errors with function return values of error. 4. Run the program using the command below and repeat the steps above until you are satisfied your program output meets the above requirements.

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter7: File Handling And Applications
Section: Chapter Questions
Problem 1GZ
icon
Related questions
Question
100%
2. Create a contacts module to meet the following requirements:
i. Create a file named contacts.py.
a. Define a class named Contacts.
a. Define a member function named_init_ to meet the following requirements:
a. Take a self as a positional parameter.
b. Take a filename as a keyword parameter.
c. Set a member variable equal to the filename.
d. Set a member varialbe equal to an empty data dictionary.
e. Open the filename and load the JSON decoded contents to the empty data dictionary.
f. Cleanly manage the FileNotFoundError if the filename does not exist.
b. Define a member function named add_contact to meet the following requirements:
a. Take a self as a positional parameter.
b. Take a id as a keyword parameter.
c. Take a first_name as a keyword parameter.
d. Take a last_name as a keyword parameter.
e. If the id exists in the data dictionary, return the string error.
f. Set the id:[first_name, last_name] key:value pair to the data dictionary.
g. Sort the data dictionary in ascending order by last name, and then by first name, ignoring
case.
h. Write the contents of the data dictionary to the filename that was set to the member
variable.
i. Return the key:value pair that was added.
c. Define a member function named modify_contact to meet the following requirements:
a. Take a self as a positional parameter.
b. Take a
c. Take a
d. Take a last_name as a keyword parameter.
e. If the id does not exists in the dictionary, return the string error.
id as a keyword parameter.
first_name as a keyword parameter.
f. Set the id:[first_name, last_name'] key:value pair to the contact dictionary.
g. Sort the data dictionary in ascending order by last name, and then by first name, ignoring
case.
h. Write the contents of the data dictionary to the filename that was set to the member
variable.
i. Return the key:value pair that was modified.
d. Define a member function named delete_contact to meet the following requirements:
a. Take a self as a positional parameter.
b. Take a id as a keyword parameter.
c. If the id does not exists in the dictionary, return the string error.
d. Remove the key:value pair with the key equal to id.
e. Write the contents of the data dictionary to the filename that was set to the member
variable.
f. Return the key:value pair with the key equal to id.
3. Create a main driver program to meet the following requirements:
i. Create a file named main.py.
ii. Import the contacts module.
iii. Instantiate a Contacts object with any default filename.
iv. Implement a menu within a loop with following choices:
a. Add contact
b. Modify contact
c. Delete contact
d. Print contact list
e. Set contact filename
f. Exit the program
v. Prompt the user for the menu choice.
vi. Prompt the user for the information needed for the appropriate Contacts member function and call the
function.
vii. Print out appropriate errors with function return values of error.
4. Run the program using the command below and repeat the steps above until you are satisfied your program
output meets the above requirements.
Transcribed Image Text:2. Create a contacts module to meet the following requirements: i. Create a file named contacts.py. a. Define a class named Contacts. a. Define a member function named_init_ to meet the following requirements: a. Take a self as a positional parameter. b. Take a filename as a keyword parameter. c. Set a member variable equal to the filename. d. Set a member varialbe equal to an empty data dictionary. e. Open the filename and load the JSON decoded contents to the empty data dictionary. f. Cleanly manage the FileNotFoundError if the filename does not exist. b. Define a member function named add_contact to meet the following requirements: a. Take a self as a positional parameter. b. Take a id as a keyword parameter. c. Take a first_name as a keyword parameter. d. Take a last_name as a keyword parameter. e. If the id exists in the data dictionary, return the string error. f. Set the id:[first_name, last_name] key:value pair to the data dictionary. g. Sort the data dictionary in ascending order by last name, and then by first name, ignoring case. h. Write the contents of the data dictionary to the filename that was set to the member variable. i. Return the key:value pair that was added. c. Define a member function named modify_contact to meet the following requirements: a. Take a self as a positional parameter. b. Take a c. Take a d. Take a last_name as a keyword parameter. e. If the id does not exists in the dictionary, return the string error. id as a keyword parameter. first_name as a keyword parameter. f. Set the id:[first_name, last_name'] key:value pair to the contact dictionary. g. Sort the data dictionary in ascending order by last name, and then by first name, ignoring case. h. Write the contents of the data dictionary to the filename that was set to the member variable. i. Return the key:value pair that was modified. d. Define a member function named delete_contact to meet the following requirements: a. Take a self as a positional parameter. b. Take a id as a keyword parameter. c. If the id does not exists in the dictionary, return the string error. d. Remove the key:value pair with the key equal to id. e. Write the contents of the data dictionary to the filename that was set to the member variable. f. Return the key:value pair with the key equal to id. 3. Create a main driver program to meet the following requirements: i. Create a file named main.py. ii. Import the contacts module. iii. Instantiate a Contacts object with any default filename. iv. Implement a menu within a loop with following choices: a. Add contact b. Modify contact c. Delete contact d. Print contact list e. Set contact filename f. Exit the program v. Prompt the user for the menu choice. vi. Prompt the user for the information needed for the appropriate Contacts member function and call the function. vii. Print out appropriate errors with function return values of error. 4. Run the program using the command below and repeat the steps above until you are satisfied your program output meets the above requirements.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage