Computer Science, asked by fathimamariyam7, 5 months ago


Write a program to allow user to perform any those list operation given in a menu. The menu is:
Append an element
2. Insert an element
3. Append a list to the given list
4. Modify an existing element
5. Delete an existing
Write a program to allow user to perform any those list operation given in a menu. The menu is:
Append an element
2. Insert an element
3. Append a list to the given list
4. Modify an existing element
5. Delete an existing element from its position
6. Delete an existing element with a given value
7. Sort the list in the ascending order
8. Sort the list  from its position
6. Delete an existing element with a given value
7. Sort the list in the ascending order
8. Sort the list in descending order
9. Display the list.


myList = [22,4,16,38,13]


print("The list 'myList' has the following elements", myList)
print("\nL I S T O P E R A T I O N S")
print(" 1. Append an element")
print(" 2. Insert an element at the desired position")
print(" 3. Append a list of elements to the given list")
print(" 4. Modify an existing element")
print(" 5. Delete an existing element by its position")
print(" 6. Delete an existing element by its value")
print(" 7. Sort the list in ascending order")
print(" 8. Sort the list in descending order")
print(" 9. Display the list")

choice = int(input("ENTER YOUR CHOICE (1-9): "))
print("Users Choice: ", choice )
if choice == 1:
element = eval(input("Enter the element to be appended: "))​

Answers

Answered by medogboy
11

Answer:

elif choice == 2:

   element = eval(input("Enter the element to be inserted:"))

   pos = int(input("Enter the position:"))

   myList.insert(pos,element)

   print("the element has been inserted \n")

elif choice == 3 :

   element = eval(input("Enter the List to be Appended:"))

   myList.extend(newlist)

   print("the list has been Appended\n")

elif choice == 4 :

   i = int(input("Enter the Position of the element to be modified:"))

   if i < len(myList) :

       newelement = eval(input("Enter the new Element:"))

       oldelement = myList[i]

       myList[i] = newelement

       print("the element",oldelement,"has been modified\n")

   else:

       print("Position of the element is more than the lenght of list")

elif choice == 5 :

   i = int(input("Enter the position of the element to be deleted :"))

   if i < len(myList) :

       element = myList.pop(i)

       print("The Element", element, "has been deleted /n")

   else:

       print("\n Position of the element is more than the length of the list ")

elif choice == 6 :

   element = int(input("\nEnter the element to be deleted:"))

   if element in myList:

       myList.remove(element)

       print("\n The element",element,"has been deleted\n")

   else:

       print("\nElement",element,"is not present in the list")

elif choice == 7 :

   myList.sort()

   print("\n The list has been sorted")

elif choice == 8 :

   myList.sort(reverse=True)

   print("\n The List have been Sorted in reverse order")

elif choice == 9 :

   print("\n The list is :", myList)

else:

   print("choice is not valid")

Explanation:

Similar questions