Page 331 - AI Ver 1.0 Class 9
P. 331
8. Swap the adjacent elements in the list. Print the list after swapping is done.
Ans. #swapping the adjacent value
11=[1,2,3,4,5]
print("list before change",11)
1=len(11)
if 1%2==0:
for i in range(0,1,2):
11[i], 11[i+1]=11[i+1],11[i]
else:
for i in range(0,1–1,2):
11[i],11[i+1]=11[i+1],11[i]
print("list after change",11)
9. To store only integers in a new list by copying from the given list.
Ans. l=[12,"abc",45.6,True,34,45]
l2=[]
for i in l:
if type(i)==int:
l2.append(i)
print(l2)
10. Search a specific value and display its number of occurrences in a list.
Ans. A=[10,23,45,10,12,34,10,56]
s=int(input("enter value you want to search"))
count=0
for i in A:
if i==s:
count+=1
print(s," occurs ",count," times")
Unsolved Questions
SECTION A (Objective Type Questions)
uiz
A. Tick ( ) the correct option.
1. Which of the following is not the conditional statement in Python?
a. if Statement b. if...elif...else Statement
c. if…else Statement d. None of these
2. Which of the following is a looping statement in Python?
a. for statement b. while statement
c. Both a and b d. None of these
Introduction to Python 329

