Practice problem for DS (09/03/23)

Hello guys, These are some basic problems, give it a try.
Every week the difficulty level will increase.

Q.1.) Python program to swap two elements in a list

Q.2.) Counts the number of occurrences of item 50 from a tuple
tuple = ( 50,12,13,99,15,50,67,88,69,50)

4 Likes

image

image

3 Likes

That’s amazing @sriv.ansh

@sriv.ansh
Correct :100:
Very good :+1:

1 Like



1 Like

@hareeshduddupudi

Thank you for your valuable contribution.

count = int(input(‘enter the range of the list’))

li = []

for i in range(count):

x = int(input(‘enter the element’))

li.append(x)

print()

print(li,‘\n’)

element1=int(input(‘enetr the first element to swap’))

element2=int(input(‘entre the second element to swap’))

a=li.index(element1)

b=li.index(element2)

li[a], li[b] = li[b], li[a]

print()

print(li)

tuple = (10,20,30,10,25,25,30,25,36,25,45,25)

print(tuple.count(25))

1 Like

Woow, Amazing going guys @hareeshduddupudi @sms18680 @sriv.ansh
Keep practicing

Q.1) answer:-
a=10
b=20
a,b=b,a
print(‘the value of a after swapping is=’,a)
print(‘the value of a after swapping is=’,b)
output:-
the value of a after swapping is= 20
the value of a after swapping is= 10

Q.2)tuple = ( 50,12,13,99,15,50,67,88,69,50)
print( tuple.count(50))
output:-
3

1 Like

@nagmafariyal2017
Keep it up :slightly_smiling_face:

1 Like