Informatics Practices Class 12 Question Bank Chapter wise
INTRODUCTION TO PYTHON
1. Which of the following is an assignment operator in Python?
a) ==
b) ===
c) >>>
d) =
2. What will be the output after the following statements?
x,y=6,3
print (x / y)
a) 2.0
b) 2
c) 18
d) 18.0
3. x = 83
y = 57
print (x > y, type(x>y))
Write the result of above code .
4. Solve the following expression
A=5 B=2 C = 8
w= A*2/5
x= A%B + 1 – C
y = (A+B**2) % 2
z= A//C + (B%8)
print(w,x,y,z)
5. Write Two difference between mutable and immutable data type.
6. Rewrite the following program after removing the errors in the program (Min four errrors)
Number = input(“Enter a number”)
Double the number = Number **2
PRINT(“Doublethenumber)
7. Find the output
X, Y = 25,50
print(X,Y)
Y,X=X,Y
print(X*2, Y*3)
8. Write a program to Find if a number is positive, negative or Zero.
9. Write a program to check if a number is Armstrong number of not.
CONTROL FLOW STATEMENT
10. Which keyword is used to take the control to the beginning of the loop?
a) exit
b) break
c) continue
d) None of these
11. Deduce the output of the following code.
if False and False:
print(“And Operation”)
elif True or False:
print(“Or operation”)
else:
print(“Default case”)
a) And Operation
b) Or Operation
c) Default Case
d) B and C option
12. Write Name of library for following functions (any two)
exit()
fabs()
randint()
13. What is the output generated by the following code?
a = 5
b = 10
if a < b or a < 0 and b < 0:
print(“Yes, it’s true.”)
else:
print(“No, it’s false.”)
14. Find the error in the following code segment
4=x
while x> 0
print x
x =+ 1 (Want to add one to x)
15. Rewrite the following code without using while loop
x = 4
while x > 0:
x = x – 1
print(x)
16. What is the output of the following code snippet?
str1 = ‘Mohd Firoz’
for i in str1:
if i>=’a’ and i<=’m’ :
print(i.upper(), end=”)
elifi>=’n’ and i<=’z’ :
print (i.lower(),end=”)
else :
print(“#”)
17. Judge the output of the following code snippet.
for i in range(10):
if i == 5:
break
else:
print(i, end=”#”)
18. Write a program to generate following pyramid pattern
* * * * *
* * * *
* * *
* *
*
19. Write a program for following output (table of a number which is
input by user )
3 x 1 =3
3 x 2 =6
3 x 3 =9
CONTROL FLOW STATEMENTS
20. What will be the output after the following statements?
x = 8
if x > 8:
print(20)
else:
print(10)
a) 20
b) x
c) 10
d) 8
21. Write two immutable Data Type with example.
22. Identify the data type of following variables
A,B,C,D=(10,), 10, ’10’, False
23. Write equivalent while loop
x=10
y=5
for i in range(x-y*2):
print(“%”, i)
24. n=int(input(“Enter a number”))
c=1
for c in range(1,11) :
if c==5 :
break
print(n, ‘x’, c, ‘=’, c*n)
Write the equivalent While loop
25. Find Output :
n=int(input(“Enter a number”)) # If number is 5
c=1
while c<11:
if c==5 :
break
print(n, “x”, c, “=”, c*n)
c+=1
26. Write the difference between list and dictionary 2
27. Write a program to print following ouput it input is given
Input : Python
Output :
P
Py
Pyt
Pytho
Python
28. Write a Python program to display all the prime numbers within an interval of 900 to 1000.
29. Write a program to Check a year is leap year or not.
PYTHON LIST
30. Which line is having error in following code
L1=[10,20,30,50]
L1[-1]=300
L1.append(400)
L1[4]=40
print(L1+3)
x=L1*2
31. L=[‘m’, ‘a’, ‘d’ , ‘a’, ‘m’]
With respect to above list find which of following statement will give True Result
a) L[0] == L[-1]
b) L[2] == L[-3]
c) L[:2] == L[-5:-3]
d) All of the above
32. What is the value of x after the following code executes?
x = 4
while x > 0:
print(x)
x = x – 1
33. Write difference between extend and append function of list and pop and remove function from the list.
34. What is output of following code :
x = [1, 2, 3, 4]
y = x
y[2] = 0
z = x[1 : ]
x[1] = 9
print(x, y, z)
35. Find Output of following code
x = [1]
x.append(5)
x.extend([1,2,1,3,2,4])
x.remove(2)
x.pop()
print(len(x),’:’,x)
36. Difference between del and clear? with example.
37. Find Output
L= [ “These”, “are”, “a”, [“few”, “words”], “that”, “we”,“will”, “use” ]
print(L[3:4])
print(L[3][0][1])
print(‘few’ in L)
print(“few” in L[3] == ‘few’ in “FEW MALE”)
38. Find the Correct Output List = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(“\nOriginal List:\n”, List)
print(“\nSliced Lists: “)
print(List[3:9:2])
print(List[::2])
print(List[:3] + List[5:]
39. Write a python program to exchange all the list element in such a way that even position number are replaced with their adjacent odd number position in list also fin the sum of all list elements
Original List [10, 20, 30, 40, 50, 60]
Exchanged List [20, 10, 40, 30, 60, 50]
Sum of List elemnts= 120
PYTHON DICTIONARY
40. Which of the following statements create a dictionary?
dic = {}
dic = {“charles”:40, “peterson”:45}
dic = {40: “charles”, 45: “peterson”}
All of the above
41. Which of the following can not be a dictionary keys
a) List
b) tuple
c) string
d) number
42. Assume d = {“Guido”:”Python”, “Dennis”:”C”}. To obtain the number of entries in dictionary the statement used is.
a) d.size()
b) len(d)
c) size(d)
d) len()
43. What is the output of the following code?
stuff = {“book”:”Java”, “price”:45}
print( stuff.get(“book”)
print (stuff[‘book’]
44. Guess the output of the following code.
week = {1:”sunday”, 2:”monday”, 3:”tuesday”}
for k, v in week.items():
print(k,v)
45. dictA = {1: “A”, 2: “B”, 3: “C”}
dictB = {4: “D”, 5: “E”}
dictA.update(dictB)
print(dictA)
46.What will be the output of following code-
D = dict()
for i in range (3):
for j in range(2):
D[i] = j
print(D)
47. a = {}
a[1] = 1
a[‘1’] = 2
a[1]=a[1]+1
count = 0
for i in a:
count += a[i]
print(count, i, type(i))
48. Find errors (min 6 errors)
text = ‘bracadbra” ; # 1
for words in text # 2
count[word]=count[word]+1 # 3
mydict = { 1= ”a”, 2=”b”, 3=”c”} # 4
for key in keys.mydict() : # 5
print (mydict(key)+ 2 ) # 6
49. WAP to create a dictionary named year whose keys are month names and values are their corresponding number of days.