Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def insertion():
- num=int(input("enter the no of elements\n"))
- a=list() #in python array=list
- print("enter the elements\n")
- for i in range(num):
- n=input()
- a.append(int(n)) # we put the entered elements in the list by using append()
- pos=int(input("enter the position for insertion\n"))
- ele=int(input("enter the element\n"))
- if(pos<=num):
- s=i-1
- for i in range(num-1, i >=pos,s ):
- a[i+1]=a[i]
- a[pos]=ele
- print("the inserted array is:\n")
- for i in range(num):
- print(a[i])
- insertion()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement