Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I know it looks like a lot due to the images but its actually one small program that uses Lists as a phonebook. Can someone

I know it looks like a lot due to the images but its actually one small program that uses Lists as a phonebook. Can someone help with the functions for the program. Its python. There is already half of it done. I want to know what I did wrong since lists are confusing when trying to create a book

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
o addCuntact: this function receives as a parameter the list of contacts and does not return any value The function requests the information from STDlN about the new contact using thefullowing output messages: Enter the First Name: Enter the Last Name: Enter the Phone Number: Enter the Birthday: Finally. the function appends the new contact at the end of the list. 0 deleteCuntact: this function receives as a parameter the list of contacts and does not return any value. The function requests the information from STDIN about the contact number to be deleted using the following output messages: Select the Contact to be deleted: The contact number is an integer value from 1 to n, where n is the number of contacts in the list. If the (ontatt number selected by the user is valid your program deletes the selected contact from the contact list, and outputs the following message (example for contact number equal to 1): Contact 1 deleted If the contact number selected by the user is invalid, your program prints the following message. Incorrect Contact number 0 modifyConlact: this function receives as a parameter the list of contacts and does not return any value. The function requests the information from STDIN about the contact number to be modified using the following output messages: Select the contact to be changed: The contact number is an integer value from 1 to n, where n is the number of contacts in the list. If the contact number selected by the user is valid, your program requests from STDlN the information about the contact to be modied (rst name, last name, phone number, and birthday) using the following output messages: Enter the First Name: Enter the Last Name: Enter the Phone Number: Enter the Birthday: and outputs the following message (example for contact number equal to 1): Contact 1 was changed Contact 1 was changed If the contact number selected by the user is invalid, your program prints the following message: Incorrect contact number EXAMPLE: Please note that these examples were produced using a desktop IDE, so the input is visible. In Moodle, the input will not be part of the program's output and therefore not visible. Given the previous input file (cl.txt), the expected output of your program is: Enter the file name: cl. txt 1. Print Contact List 2. Add New Contact 3. Delete Contact 4. Modify Contact 5. Exit Enter your option: 1 Contact # 1 First name: Fnamel, Last name: Lnamel, Phone number: 1234567890, Birthday: 01/01/2021 Contact # 2 First name: Fname2, Last name: Lname2, Phone number: 1234567891, Birthday: 01/02/2021 Contact # 3 First name: Fname3, Last name: Lname3, Phone number: 1234567892, Birthday: 01/03/2021 Contact # 4 First name: Fname4, Last name: Lname4, Phone number: 1234567893, Birthday: 01/04/2021 1. Print Contact List 2. Add New Contact 3. Delete Contact 4. Modify Contact 5. Exit Enter your option: 2 Enter the First Name: Fname5 Enter the Last Name: Lname5 Enter the Phone Number: 1234567894 Enter the Birthday: 01/05/2021 1. Print Contact List 2. Add New Contact 3. Delete Contact 4. Modify Contact 5. ExitSelect the contact to be deleted: 2 Contact 2 deleted 1. Print Contact List 2. Add New Contact 3. Delete Contact 4. Modify Contact 5. Exit Enter your option: 4 Select the contact to be changed: 1 Enter the First Name: Fname2 Enter the Last Name: Lname2 Enter the Phone Number : 1234567890 Enter the Birthday: 01/01/2021 Contact 1 was changed 1. Print Contact List 2. Add New Contact 3. Delete Contact 4. Modify Contact 5. Exit Enter your option: 1 Contact # 1 First name: Fname2, Last name: Lname2, Phone number: 1234567890, Birthday: 01/01/2021 Contact # 2 First name: Fname3, Last name: Lname3, Phone number: 1234567892, Birthday: 01/03/2021 Contact # 3 First name: Fname4, Last name: Lname4, Phone number: 1234567893, Birthday: 01/04/2021 Contact # 4 First name: Fname5, Last name: Lname5, Phone number: 1234567894, Birthday: 01/05/2021 1. Print Contact List 2 . Add New Contact . Delete Contact 4. Modify Contact 5. Exit Enter your option: 5# Write the user defined functions here.| filename = input("Enter the file name: ") contactList = readFromFile(filename) menuOption = 0 8 - while menuOption != 5: 9 printMenu ( ) 10 menuOption = int(input("Enter your option: ") ) 11 - if menuOption == 1: 12 printContactList (contactList) 13 - elif menuOption == 2: 14 addContact (contactList) 15 - elif menuOption == 3: 16 deleteContact (contactList) 17 - elif menuOption == 4: 18 modifyContact (contactList) 19 - elif menuOption != 5: 20 print ( "Invalid option")OBJECTIVE You will use your knowledge of functions, lists, and files to write a Python program that allows the user to manipulate the information from a phonebook. THE PROBLEM Given the Python program provided in the template file, you must write the definition and implementation of the following user-defined functions: o readFromFile: this function receives as a parameter the filename (string). The function opens the input file using the parameter "filename". Each line of the input file represents the information of a contact in the phonebook. The format of the input file is as follows: Fname1 Lnamel 1234567890 01/01/2021 Fname2 Lname2 1234567891 01/02/2021 Fname3 Lname3 1234567892 01/03/2021 Fname4 Lname4 1234567893 01/04/2021 Each line has four strings (separated by a single white space) representing the first name, the last name, the phone number, and the birthday of a person. The function creates a list of lists where each element of the list is a list that stores the information of a person. Finally, the function returns the list with all contacts. Based on the previous input file, the list returned by the function is: [[ 'Fnamel' , 'Lnamel', '1234567890', '01/01/2021'], ['Fname2' , 'Lname2', '1234567891', '01/02/2021'], ['Fname3' , 'Lname3' , '1234567892' , '01/03/2021'], ['Fname4' , 'Lname4' , '1234567893' , '( printMenu: this function does not receive any parameters and does not return a value. The function prints to STDOUT the following output messages 1. Print Contact List 2. Add New Contact 3. Delete Contact 4. Modify Contact 5. Exit o printContactList: this function receives the list with the contacts (list of lists) and does not return a value. Given the previous input file, the function prints to STDOUT contents of the list of contacts using the following output messages: Contact # 1 First name: Fnamel, Last name: Lnamel, Phone number: 1234567890, Birthday: 01/01/2021 Contact # 2 First name: Fname2, Last name: Lname2, Phone number: 1234567891, Birthday: 01/02/2021 Contact # 3 First name: Fname3, Last name: Lname3, Phone number: 1234567892, Birthday: 01/03/2021 Contact # 4 First name: Fname4, Last name: Lname4, Phone number: 1234567893, Birthday: 01/04/2021

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

=+15. How can rules be implemented with SPARQL?

Answered: 1 week ago