Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

'''

to do:
1. print a list
2. add a name to list
3. remove a item in the list
4. change an item in the list
5. quit
'''
nameList = []
while True:
print("\n\n1. Print list\n2. Add a name\n3. Remove a name\n4. Change a name\n5.
Quit")
menuItem = int(input("Enter the number from menu list: "))
length = len(nameList)
if menuItem == 1:
print("1. Print list")
if length > 0:
print(nameList)
else:
print("--List is empty")
elif menuItem == 2:
print("2. Add a name")
addName = input("--Enter name to add: ")
nameList.append(addName)
print("List: ", nameList)
elif menuItem == 3:
print("3. Remove a name")
removeName = input("--Enter name to remove: ")
for i in nameList:
if removeName == i:
nameList.remove(removeName)
print("List: ", nameList)
elif menuItem == 4:
print("4. Change a name")
findName = input("--Enter the name you want to change form list: ")
changeName = input("--Enter the name to change in list: ")
counter = 0
for i in nameList:
if findName == i:
nameList[counter] = changeName
else:
print("not found")
counter += 1
print("List: ", nameList)
elif menuItem == 5:
break

input()

You might also like