You are on page 1of 4

PRACTICLE 1: WAP to accept integer array and search a particular value in

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]

N=int(input("Enter the number to be searched:"))

for i in range(len(L)):

if type(L[i])==int and L[i]==N:

print("Exists at position:",i+1)

break

else:

print("Does not exists")


PRACTICLE 2: WAP to exchange first half elements of list with second half
PRACTICLE 1: WAP to accept integer array and search a particular value in the
elements of list assuming list is having even number of elements.

array. If it exists, then the function should display “exists”, otherwise should
OUTPUT:

display “Does not exists”.

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:

num [i], num[i+1]= num[i+1], num[i]

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]

print("After shifting list is:",l)

You might also like