Question
Need help. Please write Python program that answer the prompt and has an sample output as shown below. Thank you.

image.png
Command: view Number: 2 Name: Eric Idle Email: eric@ericidle.com Phone: +44 20 7946 0958 Command: add Name: Mike Murach Email
Specifications Your program should have the following functions: o def display(contacts) o def add(contacts) o def view(conta
image.png
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source Code :

def display(contacts):#function to display contacts
    if len(contacts) == 0:#if no contacts present
        print("No Contacts to display.\n")
        return
    else:#if contacts are present
        i = 1  # For printing the index as string on the contact
        for row in contacts:#loop for all contacts
            print("{}. {}".format(str(i), row[0]))
            i += 1#increment number to display contact number
        print()


def add(contacts):#function to add contact
    name = input("Name: ") #user input for name
    email = input("Email: ") #user input for email
    phone = input("Phone: ") #user input for phone
    contacts.append([name, email, phone])#add details to list
    print("{} was added.\n".format(name))


def view(contacts):#function to view contacts
    number = int(input("Number: ")) #input number from user
    if number <= len(contacts) + 1 and number>0:#if valid user number is provided
        contact = contacts[number - 1] #contact row
        print("Name: {}\nEmail: {}\nPhone: {}\n".format(contact[0], contact[1], contact[2]))
    else:#if number not in range
        print("Enter valid Contact Number\n")
        return


def delete(contacts):#function to delete contact
    number = int(input("Number: "))#input number from user
    name =  contacts.pop(number-1)[0]#delete contact using index
    print("{} was deleted\n".format(name))


def display_title():  # funnction to display title
    print("Contact Manager\n")


def display_menu():  # function to display menu
    print("list - Display all contacts\nview - View a contact\n"
          "add - Add a contact\ndel - Delete a contact\nexit - Exit program\n")


def main():#main program
    #2-dimensional storage of contacts
    contacts = [["Guido van Rossum", "[email protected]", "+31 0474 33 8826"],
                ["Eric Idle", "[email protected]", "+44 20 7946 0958"]]
    display_title()#function call
    display_menu()#function call
    while True:#loop untill exit
        option = input("Command:")#user input for command option
        if option == "exit":#to exit 
            print("\nThank you for using my app.")
            break#break loop
        elif option in ["list", "view", "add", "del"]: #valid options to proceed
            if option == "list":
                display(contacts)#function call
                continue
            if option == "view":
                view(contacts)#function call
                continue
            if option == "add":
                add(contacts)#function call
                continue
            if option == "del":
                delete(contacts)#function call
                continue

        else: #invalid options
            print("Enter a valid option\n")


main() #call main program

Screenshot of Code :

UUUUU def display (contacts):#function to display contacts if len(contacts) == 0:#if no contacts present print(No Contacts t

def display_title(): # funnction to display title print(Contact Manager\n) def display_menu(): # function to display menu p

Output - Screenshot :

Contact Manager list - Display all contacts view - View a contact add - Add a contact del - Delete a contact exit - Exit prog

Command: del Number: 1 Guido van Rossum was deleted Command: exit Thank you for using my app.

Note :

  • Code written in python3
  • Explanation provided in code within the comments
  • If any doubts feel free to comment here
Add a comment
Know the answer?
Add Answer to:
Need help. Please write Python program that answer the prompt and has an sample output as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the code in python, if you cannot answer all the question please dont anser, thanx very much. Please gimme a scr...

    Write the code in python, if you cannot answer all the question please dont anser, thanx very much. Please gimme a screen shot for code. Write clear code with comments and follow coding convention. Comments should include your name, student number and subject code on top of your code Question 1 Create a list to store all the subject codes that you are currently doing at UOW Then use for loop to display it in a table as in the...

  • I really need help with this python programming assignment asap please double check indentations, thank you...

    I really need help with this python programming assignment asap please double check indentations, thank you We were unable to transcribe this imageEnter a drink option: Milk 22 Guest #1: a Please select the number of your entree choice 1) Planked salmon, 2) Prime rib, 3) Sesame tofu with spinach: 3 Please select the number of your dessert choice 27 1) Caramel oat bar, 2) Chocolate decadence, 3) Orange creme brulee: 1 Please select the number of your drink choice...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT