Sample Paper Class 12 Computer Science Term 1 Set B
Section A
1. Which function returns the value for the given key, if key is present in the dictionary?
(a) items()
(b) get()
(c) clear()
(d) keys()
Answer
B
2. To create a dictionary in Python, ………… pair is used.
(a) key : value
(b) key + value
(c) key – value
(d) key = value
Answer
A
3. All the errors that are detected and displaced by the compiler or interpreter are known as
(a) run-time errors
(b) compile-time errors
(c) logical errors
(d) None of these
Answer
B
4. Which of the following is/are Python syntax error?
(a) Leaving out a keyword
(b) Misspelling a keyword
(c) Incorrect indentation
(d) All of these
Answer
D
5. The collection of functions creates a
(a) program
(b) software
(c) recursion
(d) library
Answer
A
6. Which of the following is/are built-in function(s)?
(a) type ()
(b) input ()
(c) print ()
(d) All of these
Answer
D
7. Which function is used to generate a sequence of numbers overtime?
(a) range()
(b) len()
(c) limit()
(d) lim()
Answer
A
8. ……… statements enable a program with a cyclic flow of logic.
(a) Sequence
(b) Compound
(c) Single
(d) Iterative
Answer
D
9. What is the output of the following code?
num=4+float(7)/int(2.0)
print(num)
(a) 6.5
(b) 7.5
(c) 7
(d) 5
Answer
B
10. What is the minimum number of iterations that while loop could make?
(a) 1
(b) 2
(c) −1
(d) 0
Answer
D
11. Identify the output of below code.
l1=list()
print(l1)
(a) []
(b) Error
(c) (,)
(d) ()
Answer
A
12. Which method is used to convert string into tuple?
(a) string()
(b) convert()
(c) replace()
(d) tuple()
Answer
D
13. Riya intends to position the file pointer to the beginning of a text file. Identify the Python statement for the same assuming F is the FileObject.
(a) F.load(0)
(b) F.dump(0)
(c) F.seek(0)
(d) F.pickle()
Answer
C
14. The function pow(x,y,z) is evaluated as
(a) (x**y)**z
(b) (x**y) / z
(c) (x**y) % z
(d) (x**y)*z
Answer
C
15. What will be the output of the following Python function?
sum(6, 2, 7)
sum([3, 8, 6])
(a) Error, 17
(b) 15, Error
(c) 15,7
(d) Error, Error
Answer
A
16. To read the entire remaining contents of the file as a string from a file object f, we use ……… .
(a) f.read(5)
(b) f.read()
(c) f.readline()
(d) f.readlines()
Answer
B
17. What will be the output of the following Python code?
>>>“Welcome to Study Corner”.split()
(a) [“Welcome”,“ to”,“ Study”,“ Corner”]
(b)( “Welcome”,“ to”,“ Study“,“ Corner”)
(c) {“Welcome”,“ to”, “Study”, “Corner”}
(d) “Welcome”, “to”, “Study”, “Corner”
Answer
A
18. What is the data type of (1)?
(a) Tuple
(b) Integer
(c) Both (a) and (b)
(d) List
Answer
B
19. The process of pickling in Python includes
(a) conversion of a list into a datatable
(b) conversion of a byte stream into Python object hierarchy
(c) conversion of a Python object hierarchy into byte stream
(d) conversion of a datatable into a list
Answer
C
20. Read the following Python code carefully and point out the global variables?
a, b = 25,12
def test():
global i
i = a+b
(a) i
(b) a and b
(c) i, a and b
(d) Neither i nor a nor b
Answer
C
21. Which of the following expression is an example of type conversion?
(a) 2.0 + float(5)
(b) 6.8 + 9.8
(c) 11.0 + 9
(d) 23 + 5
Answer
A
22. What will be the output of the following Python code?
print(‘@Study12#Corner!’.istitle())
(a) True
(b) False
(c) Error
(d) None
Answer
A
23. What will be the output of the following code?
L1=[7, 2, 3, 4]
L2=L1+2
print(L2)
(a) [9, 4, 5, 6]
(b) [7, 2, 3, 4, 2]
(c) [2, 7, 2, 3, 4]
(d) Error
Answer
D
24. Identify the for loop condition is to be repeated 100 times.
(a) for i in range (0,100) :
(b) for i in range (1,100) :
(c) for i in range (0,100+1) :
(d) for i in range (1,100+2) :
Answer
A
25. Observe the tuple and find the output.
t1=(4, 7, 8, 9)
t2=(0, 4, 3)
t=t1*t2
print(t)
(a) (4, 7, 8, 9, 0, 4, 3)
(b) (0, 4, 3, 4, 7, 8, 9)
(c) (4, 7, 0, 4, 3, 8, 9)
(d) Error
Answer
D
Section B
26. Which of the following statement opens a binary file ‘test.bin’ in write mode and writes data from a tuple t1=(2, 5, 8, 2) on the binary file?
(a) with open(‘test.bin’,‘wb’)as f:
pickle.dump(t1, f)
(b) with open(‘test.bin’,‘wb’)as f:
pickle.dump(f,t1)
(c) with open(‘test.bin’,‘wb+’)as f:
pickle.dump(f,t1)
(d) with open(‘test.bin’,‘ab’)as f:
pickle.dump(f,t1)
Answer
A
27. What will be the output of following code?
w=90
while (w>60):
print(w)
w=w−40
(a) 60
(b) 50
(c) 90
(d) 90
50
Answer
C
28. What will be the output of the following Python code?
val = [[4, 9, 6, 3], [2,6, 7,4]]
a = val[0][0]
for i in val:
for j in i:
if a> j:
a = j
print(a)
(a) 2
(b) 3
(c) 5
(d) 6
Answer
A
29. What will be the output of the following Python code?
def test(a):
print(a+1)
a= − 3
a=6
test(25)
(a) 26
(b)10
(c) 2
(d) 25
Answer
A
30. What will be the output of the following Python code?
def test(x):
x = [5]
a = [1]
test(a)
print(a)
(a) [1]
(b) [5]
(c) [5, 1]
(d) [1, 5]
Answer
A
31. What will be the output of the following Python code snippet?
N1 = {}
N2 = {}
N3 = {}
n1[1] = 6
n1[3] = 7
n2[4] = ‘B’
n3[‘Numbers’] = n1
n3[‘Letters’] = n2
print(n3)
(a) {‘Numbers’: {1: 6, 3: 7}, ‘Letters’: {4: ‘B’}}
(b) ‘Numbers’: {1: 6, 3: 7}
(c) {‘Numbers‘: {1:6}, ‘Letters’: {4: ‘B’}}
(d) Error, dictionary in a dictionary cannot exist
Answer
A
32. What will be the output of the following Python code snippet?
x =‘pqrs’
for i in range(len(x)):
x = ‘p’
print(x)
(a) p
(b) pqrspqrspqrs
(c) pppp
(d) Error
Answer
C
33. Choose the correct option from the following, when program will be run.
myfile = open(“story.txt”, “rw+”)
for index in range(5):
line = myfile.next( )
print(“Line No %d %s” % (index, line))
myfile.close( )
(a) It gives compilation error
(b) It gives syntax error
(c) It displays output
(d) None of the mentioned
Answer
C
34. What is the result of following expression?
A=3*4//5+5//7+8−2+4//2
(a) 12
(b) 10
(c) 8
(d) 14
Answer
B
35. Find the output of the following code.
num=123
f=0
s=0
while(num > 3):
rem = num % 100
if(rem % 2 ! = 0):
f + = rem
else:
s + = rem
num / =100
print(f−s)
(a) 21
(b) 13
(c) 23
(d) 24
Answer
C
36. What will be the output of following code?
str1=“Hello Arihant”
cn=0
for i in str1:
cn=cn+1
new=str1[0:2]+str1[cn−2:cn]
print(new)
(a) Helo
(b) Arnt
(c) Hello
(d) Hent
Answer
D
37. Consider the following code :
f = open (“mytry”,“w+”)
f.write(“0123456789abcdef”)
f.seek(−3,2) #Statement 1
print(f.read(2)) #Statement 2
Give the output of Statement 2.
(a) ab
(b) bc
(c) cd
(d) de
Answer
D
38. What will be the output of the following code?
import random
X=random.random( )
Y=random.randint(0, 4)
print(int(X), “:”, Y+int(X))
(a) 0:0
(b) 1:6
(c) 2:4
(d) 0:4
Answer
A
39. What is the output of following code?
def test (a, b):
x=a*b
print(x)
n1=23
n2=2
test(n1, n2)
(a) 25
(b) 23
(c) 46
(d) 23, 2
Answer
C
40. Riya is working on file handling in which her file’s working directory is Users\Arihant in drive C. Identify the output of following code snippet.
import os
s=os.getcwd( )
print(“%s”, s)
(a) C:\Arihant
(b) C:\Users\Arihant
(c) D:\Arihant
(d) D:\Users\Arihant
Answer
B
41. What will be the output of following code, if value of L is [2, 3, 5, 1, 7] ?
def oddtoeven(L):
for i in range(len(L)):
if(L[i]%2 !=0):
L[i] = L[i]*2
print(L)
(a) [4, 6, 10, 2, 14]
(b) [2, 6, 10, 2, 14]
(c) [2, 1, 3, 5, 7]
(d) Error
Answer
B
42. What will be the output of the following Python code?
i = 1
while i < 5:
print(i)
i += 1
else:
print(1)
Answer
B
43. What will be the output of the following Python code?
a=(23, 56, 12, 62, 23)
b=slice(0,2)
print(a[b])
(a) Invalid syntax for slicing
(b) [23, 12]
(c) (23, 56)
(d) (23, 56, 12)
Answer
C
44. What will be the output of the following Python code?
def test(c):
return c * 9/5 + 32
print(test(120))
print(test(O))
(a) 248.0
32.0
(b) 256.0
64
(c) 32.0
248.0
(d) 32.0
32.0
Answer
A
45. What will be the output of the following Python code snippet?
dic1 = {1:‘One’, 2:‘Two’, 3:‘Three’}
dic1 = {}
print(len(dic1))
(a) 1
(b) 0
(c) 3
(d) 2
Answer
B
46. What is the output of following code?
t1=(4,)
t2=( )
t=t1+t2
any(t)
(a) False
(b) True
(c) 0
(d) Error
Answer
B
47. Suppose the content of file ‘‘para.txt’’ is What will be the output of code?
f=open(“para.txt”, ‘r’)
a=f.read( )
print(len(a))
f.close( )
(a) 25
(b) 23
(c) 22
(d) 26
Answer
A
48. Identify the error in following statements if any.
a=int(input(“Enter a:”)) # Statement 1
b=0 # Statement 2
c=a/b # Statement 3
(a) Statement 1
(b) Statement 2
(c) Statement 3
(d) None of these
Answer
C
49. What will be the output of following code?
list1=[2, 5, 4, [9, 6], 3]
list1[3][2] =10
print(list1)
(a) [2, 5, 4, [9, 10], 3]
(b) [2, 5, 4, 10, [9, 6], 3]
(c) Index out of range
(d) None of these
Answer
C
Section C
Case Study Based Questions
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
import os
def countopen():
if os.path.isfile(“start.txt”):
______=open(“start.txt”,“r”) # line 1
c=0
print(“The lines are:”)
while True:
l=f.______() # line 2
l=l.______() # line 3
print (l)
if not l:
______ # line 4
list1=l.upper().split()
if(list1[0]______ ‘OPEN’): # line 5
c=c+1
if(______): # line 6
print(“Total lines started with
the word ‘OPEN’ is/are:”,c)
else:
print(“There is no line started
with the word ‘OPEN’ ”)
f.close()
else:
print(“File does not exist”
50. Choose the correct option to fill up the blank in line 1 as marked
(a) l
(b) f
(c) r
(d) c
Answer
B
51. Choose the correct option to fill up the blank in line 2 as marked
(a) read ()
(b) read (n)
(c) redline ()
(d) readlines ()
Answer
C
52. Choose the correct option to fill up the blank in line 3 as marked
(a) strip ()
(b) lstrip ()
(c) rstrip ()
(d) isdigit ()
Answer
C
53. Identify the missing statement to fill up the blank in line 4 as marked
(a) continue
(b) break
(c) flag
(d) label
Answer
B
54. Choose the correct option to fill up the blank in line 5 as marked
(a) i =
(b) > = 0
(c) < = 0
(d) = =
Answer
D
55. Choose the correct condition to fill up the blank in line 6.
(a) C ! = 0
(b) C < = 0
(c) C > 0
(d) C < 0
Answer
C