KnowledgeBoat Logo
LoginJOIN NOW

Informatics Practices

Write a program in Python to input elements in an empty list. Also delete an element from the list which a user will input.

Python List Manipulation

2 Likes

Answer

m = []
n = int(input("Enter the number of elements in list: "))
for i in range(n):
    element = input("Enter an element to add to the list: ")
    m.append(element)
print("List before deletion:", m)
e = input("Enter the element to delete from the list: ")
m.remove(e)
print("List after deletion:", m)

Output

Enter the number of elements in list: 5
Enter an element to add to the list: 3
Enter an element to add to the list: 6
Enter an element to add to the list: 9
Enter an element to add to the list: 12
Enter an element to add to the list: 15
List before deletion: ['3', '6', '9', '12', '15']
Enter the element to delete from the list: 12
List after deletion: ['3', '6', '9', '15']

Answered By

3 Likes


Related Questions