# Menu Driven Program to implement all user defined functions of a list in Python

### Menu Driven Program to implement all user defined functions of a list in Python

ch=’y’
L = [1,2,3,4,2,3,2,4,5,6,71,1,10,12]
while ch == ‘y’ or ch==’Y’:
print(“1. append in list”)
print(“2. Insert in a list”)
print(“3. Find length of list”)
print(“4. To count occurence of an element”)
print(“5. Extend a list”)
print(“6. Find the sum of list elements”)
print(“7. Find the index of given element”)
print(“8. Find the minimum element in a list”)
print(“9. Find the maximum element in a list”)
print(“10.To pop element”)
print(“11.To remove element”)
print(“12.To use del”)
print(“13.To reverse a list”)
print(“14.To sort a list”)
x = int(input(“Enter choice = “))
if x == 1:
print(“Original list “, L)
val = int(input(“Enter a value to be appended -> “))
L.append(val)
print(“List after append “, L)
if x == 2:
val = int(input(“Enter a value to be inserted -> “))
loc = int(input(“Enter a location to insert -> “))
L.insert(loc,val)
print(“Original list “, L)
print(“List after insert”,L)
if x == 3:
n = len(L)
print(“Length of list “,n)
if x == 4:
val = int(input(“Enter a value whose occurence want to count -> “))
n = L.count(val)
print(val,” occur “,n,”times in list”, L)
if x == 5:
M = [100,200,300,4000]
L.extend(M)
print(“List after extend “,L)
if x == 6:
n = sum(L)
print(“Sum of list elements “,n)
if x == 7:
print(L)
print(“1. To give index when no stariing and ending value given”)
print(“2. To give index after given staring index value”)
print(“3. To give index after given staring and ending index value”)
y = int(input(“Enter choice -> “))
if y == 1:
val = int(input(“Enter a value whose index you want -> “))
n = L.index(val)
print(“index of “, val,” is “, n)
if y == 2:
val = int(input(“Enter a value whose index you want -> “))
loc = int(input(“Enter a staring location -> “))
n = L.index(val,loc)
print(“index of “, val,” is “, n)
if y == 3:
val = int(input(“Enter a value whose index you want -> “))
loc = int(input(“Enter a staring location -> “))
end = int(input(“Enter a ending location -> “))
n = L.index(val,loc,end)
print(“index of “, val,” is “, n)
if x == 8:
n = min(L)
print(“Minimum element of list “,n)
if x == 9:
n = max(L)
print(” maximum element of list “,n)
if x == 10:
print(“1. To pop last element “)
print(“2. To pop a particular index”)
y = int(input(“Enter the choice”))
if y == 1:
print(“List before pop “,L)
n = L.pop()
print(“List after pop “,L)
if y == 2:
loc = int(input(“Enter a location to pop -> “))
print(“List before pop “,L)
n = L.pop(loc)
print(“List after pop “,L)
if x == 11:
print(“List before remove “,L)
val = int(input(“Enter a value want to remove -> “))
L.remove(val)
print(“List after remove “,L)
if x == 12:
print(“1. To delete complete list”)
print(“2. To delete a particular element from list”)
y = int(input(“Enter the choice”))
if y == 1:
print(“List before del “,L)
del L
print(“List after del “,L)
if y == 2:
print(“List before pop “,L)
loc = int(input(“Enter a location of element to delete -> “))
del L[loc]
print(“List after del “,L)
if x == 13:
print(“List before reverse”,L)
L.reverse()
print(“List after reverse “,L)
if x == 14:
print(“List before sort”,L)
L.sort()
print(“List in ascending order “,L)
L.sort(reverse=True)
print(“List in descending order “,L)
ch = input(“\n Do you want to continue Y/N = “)