What Is Output Of Following Python C.ode?
def findpos(AR,item):
size=len(AR)
if item<AR[0]:
return 0
else:
pos=-1
for i in range(size-1):
if (AR[i]<=item and item<AR[i+1]):
pos=i+-1
break
if (pos==-1 and i <=size-1):
pos=size
return pos
def Shift(AR,pos):
AR.append(None)
size=len(AR)
i=size-1
while i >=pos:
AR[i]=AR[i-1]
i=i-1
mylist=[10,20,30,40,50,60,70]
print("The list in sorted order is",mylist)
Item=int(input("Enter new element to be inserted:"))
position=findpos(mylist,Item)
Shift(mylist,position)
mylist[position]=Item
print("The list after inserting",Item,"is",mylist)
Answers
Answer:
After Running Above Python C.ode The Output
produced is Given in The Above Attachment.
Python Version is Python Anaconda this time.
The Answer is an Original answer by Me.
after Interpreting C.odes .
May help future python aspirant. . . . . . .
Answer:
def findpos(AR,item):
size=len(AR)
if item<AR[0]:
return 0
else:
pos=-1
for i in range(size-1):
if (AR[i]<=item and item<AR[i+1]):
pos=i+-1
break
if (pos==-1 and i <=size-1):
pos=size
return pos
def Shift(AR,pos):
AR.append(None)
size=len(AR)
i=size-1
while i >=pos:
AR[i]=AR[i-1]
i=i-1
mylist=[10,20,30,40,50,60,70]
print("The list in sorted order is",mylist)
Item=int(input("Enter new element to be inserted:"))
position=findpos(mylist,Item)
Shift(mylist,position)
mylist[position]=Item
print("The list after inserting",Item,"is",mylist)