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.

Class 12 Computer Science Sample Paper Term 1
Sample Paper Class 12 Computer Science Term 1 Set A
Sample Paper Class 12 Computer Science Term 1 Set B
Sample Paper Class 12 Computer Science Term 1 Set C
Sample Paper Class 12 Computer Science Term 2 Set A

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:
(A) Using readline ( )
(B) Using readlines ( )
(C) Using ‘,’ after every print statement
(D) Both (A) & (B)

Answer

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)

Answer

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”)

Answer

A

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

Answer

B

5. The default file open mode in Python is
(A) Write
(B) Read
(C) Append
(D) Read/write

Answer

B

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

Answer

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)

Answer

C

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

Answer

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()

Answer

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+

Answer

B

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

Answer

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

Answer

B

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

Answer

C

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

Answer

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

Answer

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

Answer

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.

Answer

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

Answer

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

Answer

B

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

Answer

A

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

Answer

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

Answer

B

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

Answer

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)

Answer

C

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

Answer

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

Answer

C

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

Answer

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

Answer

A

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

Answer

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

Answer

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.

Answer

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

Answer

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

Answer

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 ( ))
    print (fh. read (25))
(A) First 25 bytes of the file
(B) No output
(C) Syntax Error
(D) None of these

Answer

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

Answer

B

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

Answer

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.

Answer

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

Answer

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

Answer

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.

Answer

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

Answer

C

43. Predict the output of the following lines of code:
import os
fh=open(“Game.txt“)
fh.read(50)
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

Answer

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

Answer

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

Answer

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)
str=fh.read( )
print(str)
(A) This
(B) Exam
(C) E
(D) Ex

Answer

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) Elements of ‘text’ will be added after already existing contents.

Answer

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

Answer

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

Answer

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

Answer

C

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

Answer

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

Answer

B

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

Answer

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

Answer

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

Answer

C

Sample Paper Class 12 Computer Science

Related Posts

error: Content is protected !!