Write a program to read a list of elements. Input an element from the user that has to be inserted in
the list. Also input the position at which it is to be inserted. Write a user defined function to insert the
element at the desired position in the list.
Answers
Answer:
hi...its a python program
Explanation:
def list_elements(lists,element,position):
lists.insert(position,element)
return lists
#main
l=eval(input("enter the list"))
el=eval(input("enter the element"))
pos=int(input("enter the position"))
print(list_elements(l,el,pos))
#hope it helps you
please mark brainliest
The following codes are written in Python.
Source code:
n = int(input("Enter the number of elements you'd like to enter: "))
l = list()
for i in range(n):
x = eval(input("Enter the element: "))
l.append(x)
print(l, "is the final list.")
print()
ip = int(input("Enter the index position: "))
ne = eval(input("Enter the new element: "))
l.insert(ip, ne)
print()
print(l, "is the new list.")
insert() is a function that enables users to insert an element into a list.
It's syntax is as follows:
list_name.insert(new element, index position)