Professional Documents
Culture Documents
the array. If it exists, then the function should display “exists”, otherwise
should display “Does not exists”.
OUTPUT:
CODING:
L=[10,20,3,100,65,87,2]
for i in range(len(L)):
print("Exists at position:",i+1)
break
else:
array. If it exists, then the function should display “exists”, otherwise should
OUTPUT:
CODING:
L=[10,20,30,40,50,60,70]
x=int(len(L)/2)
for i in range(x):
L[i],L[x+i]=L[x+i],L[i]
print(L)
PRACTICLE 3: A list Num contains the following elements:
3, 21, 5, 6, 14, 8, 14, 3
WAP to swap the content with next value divisible by 7 so that the
resultant array will look like:
3, 5, 21, 6, 8, 14, 3, 14
OUTPUT:
CODING:
num=[3,21,5,6,14,8,14,3]
L=len(num)
i=0
while i<L:
if num[i]%7==0:
i=i+2
else:
i=i+1
print(num)
PRACTICLE 4: WAP to shift the negative numbers to left and the positive
numbers to right so that he resultant list will look like.
Original list [-12, 11, -13, -5, 6, -7, 5, -3, -6]
Output should be [ 11, 6, 5, -6, -3, -7, -5, -13, -12]
OUTPUT:
CODING:
l=[-12,11,-13,-5,6,-7,5,-3,-6]
n=len (l)
print("Original list:",l)
for i in range(n-1):
for j in range(n-i-1):
if l[j]<0:
l[j],l[j+1]=l[j+1],l[j]