CPSC223 Lab 3

$25.00

Original Work ?

Download Details:

  • Name: Lab_3-1wknej.zip
  • Type: zip
  • Size: 220.83 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

1. Write a Python program that performs as an Employee Contact List which
contains a list of contacts that can be modified or deleted.

2. Create a contacts module to meet the following requirements:
i. Create a file named contacts.py.
ii. Add a comment at the top of the file which indicates your name, date and
the purpose of the file.

iii. Note: All contact dictionaries within this module should assume a
dictionary of the form: {id: [‘first’, ‘last’], id: [‘first’, ‘last’],
id: [‘first’, ‘last’]…} where the id will be the phone number in this
exercise.

iv. Note: All functions should implement a docstring with a simple sentence
that describes the function.

v. Define a function named add_contact to meet the following requirements:
a. Take a contact dictionary as a positional parameter.
b. Take an 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 dictionary, return the string error.
f. Append the id:[first_name, last_name] key:value pair to the contact
dictionary.
g. Return the value that was added.

vi. Define a function named modify_contact to meet the following
requirements:
a. Take a contact dictionary as a positional parameter.
b. Take an 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 exist in the dictionary, return the string error.
f. Update the value of the key id with the provided first_name and
last_name
g. Return the value that was added.

vii. Define a function named delete_contact to meet the following
requirements:
a. Take a contact dictionary as a positional parameter.
b. Take an id as a keyword parameter.
c. If the id does not exist in the dictionary, return the string error.
d. Remove the key:value pair with the key equal to id.
e. Return the deleted value with the key equal to id.

viii. Define a function named sort_contacts to meet the following
requirements:
a. Take a contact dictionary as a positional parameter.
b. Sort the dictionary in ascending order by last name, then by first
name and return the sorted dictionary.

ix. Define a function named find_contact to meet the following requirements:
a. Take a contact dictionary as a positional parameter.
b. Take a find as a keyword parameter.
c. Create an empty dictionary.

d. If find is a numeric value and contained as a key in the dictionary,
add the key:value pair to the created dictionary.
e. Loop through all the key:value pairs and if the β€˜find’ substring is
contained in either the first name or last name, add that key:value
pair to the created dictionary.

f. Sort the created dictionary in ascending order by last name then
first name. Return the created dictionary.

3. Create a main driver program to meet the following requirements:
i. Create a file named main.py.
ii. Add a comment at the top of the file which indicates your name, date and
the purpose of the file.
iii. Import the contacts module.

iv. Define a variable to use for the contact dictionary.
v. Implement a menu within a loop with following choices:
a. Add contact
b. Modify contact
c. Delete contact
d. Print contact list
e. Find contact

f. Exit the program
vi. Prompt the user for the menu choice.
vii. Prompt the user for the information needed for the
appropriate contacts function and call the function.
viii. Print out appropriate errors with function return values of error.

4. Run and test the program until you are satisfied your program output meets the
above requirements.
Typical input and output for the program:
*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 1
Enter phone number: 7145551212
Enter first name: Steve
Enter last name: Jobs
Added: Steve Jobs.

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 4
==================== CONTACT LIST ====================
Last Name First Name Phone
==================== ==================== ==========
Jobs Steve 7145551212

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 1
Enter phone number: 7145551212
Enter first name: Bill
Enter last name: Gates
Phone number already exists.

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 2
Enter phone number: 7145551212
Enter first name: Bill
Enter last name: Gates
Modified: Bill Gates.

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 4
==================== CONTACT LIST ====================
Last Name First Name Phone
==================== ==================== ==========
Gates Bill 7145551212

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 2
Enter phone number: 5551212
Enter first name: Richard
Enter last name: Stallman
Phone number does not exist.

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 3
Enter phone number: 5551212
Invalid phone number.

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 3
Enter phone number: 7145551212
Deleted: Bill Gates.

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 4
==================== CONTACT LIST ====================
Last Name First Name Phone
==================== ==================== ==========

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 1
Enter phone number: 7145551111
Enter first name: Alpha
Enter last name: Jobs
Added: Alpha Jobs.

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 1
Enter phone number: 7145552222
Enter first name: Steve
Enter last name: Jobs
Added: Steve Jobs.

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 1
Enter phone number: 5625553333
Enter first name: Bill
Enter last name: Gates
Added: Bill Gates.

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 4
==================== CONTACT LIST ====================
Last Name First Name Phone
==================== ==================== ==========
Gates Bill 5625553333
Jobs Alpha 7145551111
Jobs Steve 7145552222

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 5
Enter search string: jobs
================== FOUND CONTACT(S) ==================
Last Name First Name Phone
==================== ==================== ==========

Jobs Alpha 7145551111
Jobs Steve 7145552222
*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 5
Enter search string: 5625553333
================== FOUND CONTACT(S) ==================
Last Name First Name Phone
==================== ==================== ==========
Gates Bill 5625553333

*** EMPLOYEE CONTACT MAIN MENU
1. Add contact
2. Modify contact
3. Delete contact
4. Print contact list
5. Find contact
6. Exit the program
Enter menu choice: 6

Submission
When completed, upload the following two files to Canvas:
main.py
contacts.py