Computer Science, asked by rudrakshbali215, 18 days ago

Write a menu driven program which creates an empty list and gives the following options to the user to perform various operations on the list:
(i) Input an element and a location from the user and insert the element at the entered location in the list.
(ii) Input a location from the user and remove the element from that location in the list. (iii) Input an element from the user and find its location in the list.
(iv) Display the list in sorted order without sorting the list.
(v) Display the list in reverse order without reversing the list.
(vi) Display the list
The program should terminate when the user chooses the option to exit.

Answers

Answered by anmolsingh0753
1

Answer:

list1=[]

System=True

while System==True:

   print("1) Enter an element in the list")

   print("2) Delete an element from the list")

   print("3) Find an element in the list")

   print("4) Display list in ascending order")

   print("5) Display list in descending order")

   print("6) End program")

   print("Choose an appropriate option:",end="")

   answer=int(input(""))

   if answer==1:

       element=input("Enter the element:")

       location=int(input("Position of the element in the list:"))

       if len(list1)<location:

           list1.append(element)

       else:

           list1[location-1]=element

   if answer==2:

       location=int(input("Enter the position of element in list:"))

       list1.pop(location-1)

   if answer==3:

       element=input("Enter the element:")

       if element not in list1:

           print("Element not in the list!")

       else:

           print(element,"is at","place",list1.index(element)+1,"in the list")

   if answer==4:

       print("[",end="")

       for i in list1:

           if list1.index(i)!=len(list1)-1:

               print(i,end=",")

           else:

               print(i,end="]\n")

   if answer==5:

       print("[",end="")

       for i in range(len(list1)-1,-1,-1):

           if i!=0:

               print(list1[i],end=",")

           else:

               print(list1[i],end="]\n")

   if answer==6:

       System=False
Explanation:

Similar questions