English

Write a function remove_element() in Python that accepts a list L and a number n. If the number n exists in the list, it should be removed. If it does not exist, - Computer Science (Python)

Advertisements
Advertisements

Question

Write a function remove_element() in Python that accepts a list L and a number n. If the number n exists in the list, it should be removed. If it does not exist, print a message saying “Element not found”.

Code Writing
Advertisements

Solution

def remove_element(L, n):
  if n in L:
     L.remove(n)
     print(L)
  else:
     print("Element not found")
shaalaa.com
  Is there an error in this question or solution?
2025-2026 (March) Board Sample Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×