Class 12 Computer Science Sample Paper Term 1 Set B

Sample Paper Class 12

Section A

1. Which of the following is/are jump statement(s)?
(a) break
(b) continue
(c) Both (a) and (b)
(d) None of these

Answer

C

2. Consider the declaration a= {1: ‘A’, 2: ‘B’}, which of the following represents the data type of a?
(a) list
(b) dictionary
(c) tuple
(d) string

Answer

B

3. Identify the output.
>>> a = ‘1234’
>>>type(a) is not str
(a) False
(b) True
(c) 0
(d) − 1

Answer

B

4. Which method is provided by pickle module for writing in binary files ?
(a) load ()
(b) write ()
(c) seek ()
(d) dump ()

Answer

D

5. Which standard file stream is used for standard error?
(a) sys. stderr
(b) sys.stdout
(c) sys.stdin
(d) None of these

Answer

A

6. Which function must use to read data from CSV files?
(a) read()
(b) reader()
(c) readline()
(d) readlines()

Answer

B

7. Which of the following method tells you the current position within the file?
(a) dump()
(b) load()
(c) tell()
(d) seek()

Answer

C

8. This symbol is used at the end of def line.
(a) ;
(b) !
(c) #
(d) :

Answer

D

9. ……… is a variable used to define a particular value during a function definition.
(a) Argument
(b) Parameter
(c) Both (a) and (b)
(d) None of these

Answer

B

10. This namespace includes names from various imported modules that you are using in a project.
(a) Built-in
(b) Local
(c) Global
(d) None of these

Answer

C

11. Identify the options and choose which option has an error.
(a) print(‘Hello’ *4)
(b) print(‘Hello’ +‘4’)
(c) print(2*‘R’)
(d) print(‘Hello’*‘4’)

Answer

D

12. Each individual character in a string can be accessed using a technique called
(a) traversing
(b) indexing
(c) sequencing
(d) slicing

Answer

B

13. What is the role + operator in tuple?
(a) Replicate the tuple
(b) Concatenate the tuple
(c) Slice the tuple
(d) Traverse the tuple

Answer

B

14. Which variable is defined inside any function?
(a) Local variable
(b) Global variable
(c) Both (a) and (b)
(d) None of these

Answer

A

15. What is the significance of the wb+ mode?
(a) Opens a file for writing only in binary format
(b) Opens a file for reading only in binary format
(c) Opens a file for appending in binary format
(d) Opens a file for both writing and reading in binary format

Answer

D

16. Which of the following statement is false?
(a) Global variables are declared outside of all functions.
(b) Global variables are useful for all functions.
(c) Global variables are also called global scope.
(d) Global variables are used as global namespace.

Answer

D

17. What will be the output of the following Python function?
all(5,1,3.5)
(a) True
(b) False
(c) Error
(d) None

Answer

C

18. A function that does not return any value, then what value is thrown by default when this function will be execute?
(a) int
(b) bool
(c) void
(d) None

Answer

D

19. Operators with the same precedence are evaluated in which manner?
(a) Left to Right
(b) Right to Left
(c) Cannot say
(d) None of the mentioned

Answer

A

20. What is the expansion of EOL?
(a) End of Line
(b) Enter of Line
(c) End of Large element
(d) None of these

Answer

A

21. Which of the following method returns a list of string?
(a) read()
(b) read([size])
(c) readline()
(d) readlines()

Answer

D

22. Which of the following files are used to store a large number of variables or data?
(a) Text files
(b) CSV files
(c) Binary files
(d) Data files

Answer

B

23. ….. exception is raised when result of an arithmetic operation is large.
(a) KeyError
(b) NameError
(c) OverflowError
(d) ValueError

Answer

C

24. Which of the following is invalid identifier?
(a) Name
(b) num^2
(c) num1
(d) _SUM

Answer

B

25. Identify the output of following function.
range(5)
(a) [0, 1, 2, 3, 4]
(b) [0, 1, 2, 3, 4, 5]
(c) [1, 2, 3, 4, 5]
(d) [1, 2, 3, 4]

Answer

A

Section B

26. What is the output of following code?
dic={‘A’ : 5, ‘B’ : 3, ‘C’ : 2}
res=1
for key in dic :
res=res*dic[key]
print(res)
(a) 30
(b) 10
(c) 11
(d) 17

Answer

A

27. What will be the output of the following Python code?
a= “123456”
i=“K”
while i in a:
a=a[1:]
print(i, end =“ ”)
(a) K K K K K K
(b) K
(c) No output
(d) Error

Answer

B

28. What will be the output of the following Python code?
def test(a) :
a =a +[3]
x= [6,9, 5, 3, 7]
test(x)
print(len(x))
(a) 4
(b) 5
(c) 1
(d) Error

Answer

B

29. What is the output of the following Python code?
def test():
return val +1
val= 0
print(test())
(a) 0
(b) 1
(c) Error
(d) None

Answer

B

30. Suppose the content of file “story.txt” is What is the output of the following Python code?
myfile=open(“story.txt”,‘r’)
for line in reversed(list(myfile)):
print(line. rstrip())
myfile.close()
(a) WORLD WONDER
Hello
Honesty
(b) REDNOW DLROW
olleH
ytsenoH
(c) Error
(d) Honesty
Hello
WONDER WORLD

Answer

D

31. Suppose the content of file “story.txt” is What is the output of the following Python code?
myfile = “story.txt”
with open(myfile, ‘r’) as f:
for line in f:
l=line.title()
print(l)
f.close()
(a) Wonder World
Hello
Honesty
(b) Wonder world
Hello
Honesty
(c) Wonder World
hello
honesty
(d) Wonder world
hello
honesty

Answer

A

32. What is the output of the following code?
def dic1(a):
for i in a :
print (i, “:”, a[i])
dic1 ({1 : “A” , 2 : “B”, 3 : “C”})
(a) 1 : A, 2 : B , 3 : C
(b) 1 : “A”, 2 : “B”, 3 : “C”
(c) 1 : “A”
2 : “B”
3 : “C”
(d) 1 : A
2 : B
3 : C

Answer

D

33. What is the output of following code, if List x contains 7 integers?
x=[4, 8, 7, 5, 6, 2, 10]
def test (x) :
for i in range (len(x) −1, −1, − 1):
print (x[i]*2)
(a) [20, 4, 12, 10, 14, 16, 8]
(b) [8, 16, 14, 10, 12, 4, 20]
(c) [10, 2, 6, 5, 7, 8, 4]
(d) Error

Answer

A

34. What will be the output of following code?
def test (a, b):
val = a − b
test = test (53, 40)
print(test)
(a) 13
(b) 0
(c) None
(d) Error

Answer

C

35. Evaluate the following expression and identify the correct answer.
2 + (4 − 1) *3 / /2 + 7 *3 + 10 / /3 − 2
(a) 28
(b) 22
(c) 24
(d) 32

Answer

A

36. What is the output of following code?
x=20
def output (num):
global x
x=28
if num % 5==0:
x=x+num
else:
x=x-num
print(x, end=“#”)
output (18)
print(x)
(a) 20#10
(b) 20#28
(c) 10#20#
(d) 20#5

Answer

A

37. What will be the output of the following Python code?
i = 1 
while True:
if i%5 == 0 :
break
print(i)
i += 1

Class 12 Computer Science Sample Paper Term 1 Set B
Answer

A

38. What is the output of following code?
def test(i, a = []):
a.append(i)
return a
test(25)
test(32)
s = test(17)
print(s)
(a) [25] [32] [17]
(b) [25, 32, 17]
(c) [25] [25, 32] [25, 32, 17]
(d) 25 32 17

Answer

B

39. What will be the output of the following Python code?
def test():
i=8
print(i)
i=15
test()
(a) Error
(b) 15
(c) 8
(d) 8 15

Answer

C

40. What is the output of following code?
def f1():
n=44
def f2() :
n=77
print(n)
print(n)
f1()
f2()
(a) 44
77
(b) 77
77
(c) 44
44
(d) 77
44

Answer

B

41. What is the output of following code?
dic = {}
dic[1] = 1
dic[‘1’] = 2
dic[1.0] = 4
sum = 0
for i in dic:
sum = sum + dic[i]
print(sum)
(a) 4
(b) 2
(c) 6
(d) 7

Answer

C

42. What is the output of following code?
t=(4,0, ‘Hello’, 90, ‘Two’, (‘One’, 45), 34, 2)
t1=t[1]+t[−2]
print(t1)
(a) 34
(b) 38
(c) Hello34
(d) 45

Answer

A

43. What is the output of following code?
n=5
f=1
while(n>0) :
f=f*n
n=n−1
print(f)
(a) 15
(b) 5
(c) 6
(d) 120

Answer

D

44. What is the output of following code?
t=(1, 2, ‘Hello’, ‘The’, 3, 4)
print(max(t))
(a) ‘Hello’
(b) 4
(c) ‘The’
(d) Error

Answer

D

45. What is the output of following code?
def c(x, y):
return x+y
c(3, 1.6)
(a) 3
(b) 4.6
(c) 4
(d) 1.6

Answer

B

46. Suppose the content of file ‘‘story. txt’’ is What is the output of the following Python code?
f=open (“story.txt”, ‘r’)
s=f.readlines()
print(s)
f.close()
(a) [‘Hello\n’, ‘Wonder\n’, ‘World’]
(b) [‘Hello’, ‘Wonder’, ‘World’]
(c) [‘Hello\n’, ‘Wonder\n’, ‘World\n’]
(d) [Hello\n, Wonder\n, World]

Answer

A

47. What will be the output of following code?
t=[“T”, “U”, “P”, “L”, “E”]
t1=tuple(t)
print(t1)
(a) (TUPLE)
(b) (T, U, P, L, E)
(c) (‘T’ ‘U’ ‘P’ ‘L’ ‘E’)
(d) (‘T’, ‘U’, ‘P’, ‘L’, ‘E’)

Answer

D

48. Predict the output.
dic={‘a’ : 1, ‘b’ : 2, ‘c’ : 3, ‘d’ : 4}
if ‘a’ in dic :
del dic[‘a’]
print(dic)
(a) {‘b’ : 2, ‘c’ : 3, ‘d’ : 4}
(b) {‘a’ : 1}
(c) None
(d) Error

Answer

A

49. Suppose the content of file ‘test.txt’ is What will be the output of following code?
f=open(‘test.txt’, ‘r’)
a=f.read()
print(len(a))
f.close()
(a) 10
(b) 7
(c) 13
(d) 14

Answer

C

Section C

Case Study Based Questions

Below is a program to enter a string and display new string. Answer the questions that follow to execute the program successfully.
def make (str1) :
newstr = “ ”
count = 0
for i in str1:
if count % 2 ___0: # Statement 1
newstr=newstr+str(count)
else :
if islower(___) : # Statement 2
newstr=newstr + upper ___ # Statement 3
else :
newstr=newstr+ i
count = ___ # Statement 4
newstr=___ + str1[: 1] # Statement 5
print (___) # Statement 6

50. Choose the correct option to fill the blank in Statement 1.
(a) = =
(b) > =
(c) < = 0
(d) ! =

Answer

D

51. Which value or variable will come in function islower() in Statement 2?
(a) str1
(b) i
(c) newstr
(d) count

Answer

B

52. Choose the correct option to fill the blank in Statement 3.
(a) (i)
(b) (i+1)
(c) (str1)
(d) (newstr)

Answer

A

53. Which value will be assign to variable count in Statement 4?
(a) i
(b) count −1
(c) count +1
(d) str1 +2

Answer

C

54. Choose the correct option to fill up the blank in Statement 5.
(a) str
(b) newstr
(c) count
(d) i

Answer

B

55. Choose the correct option to fill up the blank in Statement 6.
(a) newstr + 1
(b) newstr + 2
(c) newstr
(d) newstr + i

Answer

C