Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. def insertion():
  2. num=int(input("enter the no of elements\n"))
  3. a=list() #in python array=list
  4. print("enter the elements\n")
  5. for i in range(num):
  6. n=input()
  7. a.append(int(n)) # we put the entered elements in the list by using append()
  8. pos=int(input("enter the position for insertion\n"))
  9. ele=int(input("enter the element\n"))
  10. if(pos<=num):
  11. s=i-1
  12. for i in range(num-1, i >=pos,s ):
  13. a[i+1]=a[i]
  14. a[pos]=ele
  15. print("the inserted array is:\n")
  16. for i in range(num):
  17. print(a[i])
  18.  
  19.  
  20. insertion()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement