Write a program to create 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.
Answers
Answered by
4
Language:
Python
Program:
list=[]
number = int(input("Enter the value: "))
position=int(input("Enter the position: "))
list.insert(number,position)
print(f"\n{number} at index {position} has been inserted in {list}.")
Output:
Consider the attachment.
Logic:
- List initializes a list as [].
- Take input of number and position to be inserted at .
- Used insert method to enter value in the list at the position.
- Respond back if value inserted.
Attachments:
Attachments:
Similar questions