# Sample Paper Class 12 Computer Science

Please see below Sample Paper Class 12 Computer Science with solutions. These CBSE Sample Papers for Class 12 Computer Science will help you to gain more understanding of the examination style and expected paper pattern. Students should practice the below Sample Papers for Class 12 Computer Science with answers provided below. We have provided all sample papers for Standard 12 for free.

Sample Paper Class 12 Computer Science Term 1 Set A

SECTION – A

1. When reading a file line by line, the exact contents can be printed by:
(C) Using ‘,’ after every print statement
(D) Both (A) & (B)

D

2. Choose the correct Python expression for the following mathematical expressions p+q/(r+s)4
(A) p+q / math.pow ((r+s), 4)
(B) p+q/(r+s)^4
(C) p+q / math.pow (r+s,4)
(D) (p+q) / math.pow (r+s)

A

3. Identify the correct statement for opening text file data.txt in total folder of c:drive in read mode.
(A) F = open (“c:\\total\\data.txt”, “r”)
(B) F = open (“c:\total\data.txt”, r)
(C) F = open (“c:\total\data.txt”)
(D) F = open (“\total\data.txt”, “r”)

A

4. A valid combination of atoms and operators forms a Python
(A) Statement
(B) Expression
(C) Condition
(D) None of these.

B

5. The default file open mode in Python is
(A) Write
(C) Append

B

6. In Python, a block is executed in an ………………..
(A) Function
(B) Module
(C) Py file
(D) Execution frame

D

7. Consider the following code that reads a number and print its half, if it is an even number. If the number is odd, the next number is printed.
n = int (input (‘‘Enter a number :’’))
if n % 2 = = 0 :
print (‘‘The given number is even’’)
print (‘‘The half of the number is ‘‘, n/2)
else
print (‘‘The number is odd’’)
print (‘‘The next number is’’, n + 1)
Identify the statement with error in the above code.
(A) int (input (‘‘Enter a number :’’))
(B) if (n % 2 = = 0) :
(C) else
(D) print (‘‘The next number is’’, n+1)

C

8. To execute two related operations as pair python provides:
(A) Dot notation
(B) with statement
(C) with function
(D) None of these.

B

9. Which of the following string function is used to convert first character of string to capital letter?
(A) capitalize()
(B) upper()
(C) isupper()
(D) lower()

A

10. Which of the following mode should be used to:
(i) Create a file if it doesn’t exist.
(ii) Existing file is not overwritten.
(iii) Both reading and writing can be done.
Select your option so that all the above given criteria are met.
(A) r
(B) a+
(C) w+
(D) r+

B

11. What is the truth value associated with None in Python ?
(A) True
(B) False
(C) true
(D) false.

B

12. _name_ contains:
(A) name of the Python programs
(B) name of the module
(C) name of the function from the imported module
(D) name of the variables

B

13. To write an object on to a binary file use:
(B) write()
(C) dump()
(D) unpickle

C

14. A non fruitful function returns:
(A) 0
(B) Null
(C) None
(D) Void

C

15. ‘*’ operator can take which of the following set of values as operands ?
(I) 52, 36
(II) 52, ‘‘36’’
(III) ‘‘52’’, 36
(IV) ‘‘52’’, ‘‘36’’
(A) I
(B) I, II & III
(C) I & III
(D) I & IV

C

16. ………………….. is a character that separates words or phrases in a line or record.
(A) comma
(B) tab
(C) delimiter
(D) None of these

C

17. The command print (str1) give output as Hello!
How are you ?
And the command len (str1) gives output— 19.
Comment on the method of string initialization.
(A) str1 is a multiline string created with triple quotes.
(B) str1 is a multiline string created with a backslash.
(C) str1 is created with list()
(D) str1 is printed in such a way that it gives multiline output.

A

18. Python module that provides methods for file processing operations like renaming and deleting file:
(A) pickle module
(B) file module
(C) IO module
(D) OS module

B

19. Symbols that are used in programming languages to organize sentence structures, and indicate the rhythm and emphasis of expressions, statements and program structure.
(A) Tokens
(B) Punctuators
(C) Operators
(D) Literals

B

20. For every name reference within a program, Python follows a name resolution rule called
(A) LEGB
(B) LGEB
(C) BGEL
(D) GELB

A

21. Non-void functions:
(A) Return some value
(B) Return void
(C) Do not have void in function header
(D) None of these

A

22. sys.stdout.write( ) is used to write to :
(A) A file named sys.stdout
(B) Monitor
(C) File named stdout
(D) None of these

B

23. Variables defined in ‘main’ program are called
(A) Mains
(B) Global variables
(C) Main variables
(D) Local variables

B

24. Each line of text in a text file is terminated by …………………. .
(A) ‘\n’
(B) Carriage return
(C) Both (A) & (B)
(D) Neither (A) nor (B)

C

25. After -, no tasks can be performed on that file through the file object.
(A) close ()
(C) write ()
(D) open ()

A

SECTION – B

26. Predict the output of code segment given below:
when x = –1, y = –25, z = 80
x = int (input (“Enter a number”))
y = int (input (“enter another number”))
z = int (input (“Enter yet another number”))
if x < y < z :
print (“Class A”),
elif x > y > z :
print (“Class B”),
else :
print (“Class C’’),
print (“is what you get”)
(A) Class A is what you get
(B) Class B is what you get
(C) Class C is what you get
(D) None of these

C

27. Which of the following cannot be the output of random . randint (3, 10)
(A) 3
(B) 10
(C) 7
(D) 3.0

D

28. Predict the output
if 5 :
print (“smart enough”)
else :
print (“You have to be quick”)
(A) smart enough
(B) smart enough
you have to be quick
(C) smart enough you have to be quick
(D) You have to be quick

A

29. Identify the output of following expression
4*3+5-7//3+6*2–1
(A) 27
(B) 28
(C) 25
(D) 37

A

30. A file greetings.txt contains a word “GOOD”. What will be the contents of the file after execution of the following code?
fh=open(“greetings.txt”, “w”)
fh.write(“Bye“)
fh.close()
(A) Good Bye
(B) GOOD BYE
(C) GOOD Bye
(D) Bye

D

31. a = input (‘‘ Enter any number ’’)
b = input (‘‘ Enter any number ”)
c = a + b
print (c)
Predict the output of the above code if input is 56 & 72
(A) 128
(B) 5672
(C) 120
(D) Error will be displayed.

B

32. Consider the following logical expression (7 > 5) or (50 < 100/0).
What will this expression evaluate to ?
(A) Gives an error
(B) False
(C) true
(D) True

D

33. What will be the output of the following code fragment ?
out = file (“Hello. txt”, “w”)
out.write (“Hello, world /n”)
out.write (“What are you doing ?”)
out.close
file (“Hello. txt”). read ( )
(A) Hello, world
(B) Hello, world/n
(C) Hello, world/n what are you doing ?
(D) what are you doing

C

34. Predict the output
for a in range (5) :
print(a)
(A) 0
1
2
3
4
(B) 0, 1, 2, 3, 4
(C) 0 1 2 3 4
(D) 0
1
2
3
4
5

35. What is the output of the following code ?
fh.file (“Hello txt”, “r”)
size = len (fh. read ( ))
(A) First 25 bytes of the file
(B) No output
(C) Syntax Error
(D) None of these

B

36. Identify the output of following code.
x = 1998
if x % 4 == 0 :
print (“Leap year”)
else :
print (“Not leap year”)
(A) Leap year
(B) Not leap year
(C) It is not a leap year
(D) It is a leap year

B

37. What is the most probable output of randint(3, 10)?
(A) 3.045
(B) 4.789
(C) 7
(D) 10.56

C

38. What would be the output of the following lines of code?
with open (“input.txt“, ‘w’) as f:
f.write (‘Hello! Everyone‘)
(A) Syntax error
(B) File will be opened for writing, manipulated and then closed
(C) File will be opened for writing
(D) None of these.

B

39. Find the output of the following code fragment
b = 7
while (b > 0):
print (“Yes”)
b = b – 3
else:
print (“Got to go”)
(A) Yes Yes Yes
(B) Yes
Yes
Yes
(C) Got to go
Got to go Yes
Got to go Yes
(D) Yes
Got to go

D

40. str1 = “Be Good Do Good”
print(str1[10: –12: –1])
What will be the output of the above code?
(A) Syntax error
(B) Nothing will be shown
(C) oD doo
(D) None of these

C

41. Consider the code:
def minus (total, decrement)     statement 1
output=total-decrement             statement 2
return output                              statement 3
There is an error in:
(A) statement 1
(B) statement 2
(C) statement 3
(D) All of these.

A

42. What would be the output of the given code?
a = “Wow”
b = 5
c = 15
d = “29”
print(str(b)+str(c)+d+a)
(A) Syntax error
(B) 20 29 wow
(C) 51529 Wow
(D) 5 15 29 wow

C

43. Predict the output of the following lines of code:
import os
fh=open(“Game.txt“)
os.remove(“Game.txt”)
fh.close()
(A) Error
(B) After reading the file it would be deleted
(C) Nothing will happen
(D) None of these

A

44. What will be the output of the following Python code?
i=0
def change(i):
i=i+1
return i
change(1)
print(i)
(A) 1
(B) Nothing is displayed
(C) 0
(D) An exception is thrown

C

45. Is the following Python code valid?
>>> a=(1,2,3)
>>> b=a.update(4,)
(A) Yes, a=(1,2,3,4) and b=(1,2,3,4)
(B) Yes, a=(1,2,3) and b=(1,2,3,4)
(C) No because tuples are immutable
(D) No because wrong syntax for update() method

C

46. Consider a file “firts.txt” with following contents:
This is our first line.
This is our first file.
Thisis our first example.
This is our first exam.
Now read the below given code and tell us its output.
fh=open(“first.txt”)
fh.seek(–5,2)
print(str)
(A) This
(B) Exam
(C) E
(D) Ex

B

47. Consider the file “Hello.txt” containing the following data:
“This is the time of the year when the whole world around you is painted with colours of ….”
What would be the contents of the file after execution of the following lines of code?
fh = open (“Hello.txt”, “a”)
text = [“It seems everynook”, “end corners has been painted.”]
fh.writelines(text)
fh.flush( )
fh.close( )
(A) Nothing will be changed
(B) Contents of ‘text’ will be added to the beginning of file
(C) File will contain only the data of ‘text’.

D

48. What will be the output of the following Python code?
myList = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
myList[i – 1] = myList[i]
for i in range(0, 6):
print(myList[i], end = “ “)
(A) 2 3 4 5 6 1
(B) 6 1 2 3 4 5
(C) 2 3 4 5 6 6
(D) 1 1 2 3 4 5

C

49. What will be the output of the following Python code?
def foo(x):
x[0] = [‘def’]
x[1] = [‘abc’]
return id(x)
q = [‘abc’, ‘def’]
print(id(q) == foo(q))
(A) True
(B) False
(C) None
(D) Error

A

SECTION – C

CASE STUDY BASED QUESTIONS

This section consists of 6 Questions (50-55) Attempt any 5 questions.
Manjeet wrote a program to print Fibonacci series until ‘n’ value using while loop and value of n entered by user. Help him to complete code for successfully run.
n = _____ (input(“Enter the value of ‘n’: “))   # Statement 1
a = 0
b = 1
sum = ____                                                 # Statement 2
count = 1
_____ (“Fibonacci Series: “, end = “ “)           # Statement 3
while(count ___ n):                                      # Statement 4
print( ____ , end = “ “)                                # Statement 5
count += 1
a = b
b = sum
sum = _______                                           # Statement 6

50. Choose the correct option to fill up the blank in line marked as Statement 1.
(A) float
(B) string
(C) int
(D) int.input

C

51. Choose the correct option to fill up the blank in line marked as Statement 2.
(A) 1
(B) 0
(C) “ “
(D) –1

B

52. Choose the correct option to fill up the blank in line marked as Statement 3.
(A) int
(B) print
(C) output
(D) input

B

53. Choose the correct option to fill up the blank in line marked as Statement 4.
(A) !=
(B) >=
(C) <=
(D) ==

C

54. Choose the correct option to fill up the blank in line marked as Statement 5.
(A) sum
(B) count
(C) a
(D) b

A

55. Choose the correct option to fill up the blank in line marked as Statement 6.
(A) a–b
(B) b–a
(C) a+b
(D) a*b