Computer Science, asked by aara3883, 3 months ago

Write a program that display option for deleting elements in a list with option for :if element is to be deleted with value or by using its position or a list lies is to be deleted

Answers

Answered by Equestriadash
8

The following cσdes have been written using Python.

n = int(input("Enter the number of elements that are to be input: "))

print()

l = list()

for i in range(n):

   x = eval(input("Enter the element: "))

   l.append(x)

   print()

print()

print(l, "is your given list.")

print()

print("Would you like to remove an element by:")

print("1. Stating the exact value.")

print("2. Stating its position. ")

c = int(input("Enter your choice: "))

print()

if c == 1:

   y = eval(input("Enter the element that you'd like to remove: "))

   print()

   if y in l:

       l.remove(y)

       print("The element has been removed.")

   else:

       print("No such element.")

elif c == 2:

   ne = len(l)

   print("Index positions are from 0 - ", n - 1)

   y = int(input("Enter the index position of the element you'd like to remove: "))

   l.pop(y)

   print()

   print("The element has been removed.")

Similar questions