Python Suppose a list empList consists of sublists with [id,fullName] empList = [ ] Ask the user to enter their ID and name Put that information into empList Ask the user to enter a name Print the ID of the person with that name OR “Name not found” if that name isn’t in empList. Ask the user to enter a ID Remove that entry from empList OR print “No delete – name not found” if the ID isn’t there. Ask the user to enter an ID. If empList has an entry with that ID, ask the user for a newFullName and replace the existing entry in empList Print the entries in List, one per line so that the output looks like this: ID Name 123 Joe Brown 235 Molly Smith Please use format to do this printing

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Python

Suppose a  list empList consists of  sublists with [id,fullName]

empList = [ ]

  1. Ask the user to enter their ID and name
  2. Put that information into empList
  3. Ask the user to enter a name
    Print the ID of the person with that name OR “Name not found” if that name isn’t in empList.
  4. Ask the user to enter a ID
    Remove that entry from empList OR
    print “No delete – name not found” if the ID isn’t there.
  5. Ask the user to enter an ID.
    If empList has an entry with that ID, ask the user for a newFullName and replace the existing entry in empList
  6. Print the entries in List, one per line so that the output looks like this:
    ID                       Name
    123                    Joe Brown
    235                    Molly Smith   Please use format to do this printing

 

Expert Solution
Step 1
empList = []
while 1:
    print("1.Add user to list\n2.Search user by name\n3.Remove user by ID\n4.Enter the user ID for update\n5.Print the users \n6.Exit")
    choice = int(input("Enter the coice : "))
    if choice == 1:
        id = input("Enter the user ID : ")
        name = input("Enter the user name : ")
        empList.append([id,name])
    elif choice == 2:
        nametofind = input("Enter the user name : ")
        found = False;
        for i in empList:
            if nametofind in i:
                found = True
                print("ID {} Name {}".format(i[0],i[1]))
                break
        if not found:
            print("Name not found")
    elif choice == 3:
        idtoremove = input("Enter the user ID : ")
        found = False
        keyfound = []
        for i in empList:
            if idtoremove in i:
                found = True
                keyfound=i
                break
        if found:
            empList.remove(keyfound)
        else:
            print("No Delete - ID not found")
    elif choice == 4:
        idtoupdate = input("Enter the user ID : ")
        found = False
        keyfound = []
        count=0
        for i in empList:
            count+=1
            if idtoupdate in i:
                found = True
                keyfound = i
                break
        if found:
            name = input("Enter the new name : ")
            empList[count-1][1]=name
        else:
            print("ID not found")
    elif choice == 5:
        print("ID\t\tName")
        for i in empList:
            print(i[0],i[1])
    elif choice == 6:
        break
    else:
        print("Wrong input! ")
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Operations of Linked List
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning