Question #315809

Create a program that will allow the user to easily manage a list of names.


You should display a menu that will allow them to add a name to the list, change a


name in the list, delete a name from the list or view all the names in the list.



There should also be a menu option to allow the user to end the program. If they


select an option that is not relevant, then it should display a suitable message.


After they made a selection to either add a name, change a name, delete a name or


view all the names, they should see the menu again without having to restart the


program. The program should be made as easy to use as possible.

Expert's answer

choice = ''
names = []

while choice != "q":
    print("\n[1] Enter 1 to add a name to the list.")
    print("[2] Enter 2 to change a name in the list.")
    print("[3] Enter 3 to delete a name from the list.")
    print("[4] Enter 4 to view all the names in the list.")
    print("[q] Enter q to quit.")


    choice = input("\nWhat would you like to do? ")
    
    if choice == '1':
        print("\n Enter the name: ")
        name = input()
        if name in names: print("\n This name is already in the list! ")
        else:
            names.append(name)
    elif choice == '2':
        print("\n Enter the name: ")
        name = input()
        if name in names:
            print("\n Enter the new Name: ")
            for i in range(len(names)):
                if names[i] == name:
                    names[i] = input()
    elif choice == '3':
        print("\n Enter the name: ")
        name = input()
        if name in names: names.remove(name)
    elif choice == '4':
        print(*names, sep = "\n")
    elif choice == 'q':
        print("Program end")
    else:
        print("\nI don't understand that choice, please try again.\n")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS