-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListOperationsMenudriven.py
43 lines (43 loc) · 1.26 KB
/
ListOperationsMenudriven.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
n = int(input("Enter the number of items in the list:"))
print("Enter the elements:")
lst = []
for i in range(0, n):
k = int(input())
lst.append(k)
print("Menu:\n1.Display\n2.Insert\n3.Delete\n4.Search\n5.Sort")
c = int(input("Enter your choice:"))
if c == 1:
print("List elements are :", lst)
elif c == 2:
lst.append(0)
element = int(input("Enter the element to be inserted:"))
index = int(input("Enter the index value:"))
for i in range(n, index, -1):
lst[i] = lst[i - 1]
lst[index] = element
print("List elements are:", lst)
elif c == 3:
element = int(input("Enter the element to be deleted:"))
index = int(input("Enter the index value:"))
for i in range(index, n - 1):
lst[i] = lst[i + 1]
n = n - 1
print("List elements are:")
for i in range(0, n):
print(lst[i])
elif c == 4:
a = int(input("Enter the element to be searched:"))
if a in lst:
print("Element found ")
else:
print("Element not found")
elif c == 5:
for i in range(0, n):
for j in range(0, n - 1):
if lst[j] > lst[j + 1]:
temp = lst[j]
lst[j] = lst[j + 1]
lst[j + 1] = temp
print("Sorted List ", lst)
else:
print("Invalid Choice")