Class 12 Computer Science Sample Paper

Sample Paper Class 12

We have provided Class 12 Computer Science Sample Paper as per the latest CBSE examination pattern for the current academic year. The following CBSE Sample Papers for Class 12 Computer Science has been prepared based on the guess papers issued recently. Students will be able to practice these papers and get good marks in upcoming Computer Science exams for Class 12.

CBSE Sample Papers for Class 12 Computer Science

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

Class 12 Computer Science Sample Paper Term 1 With Solutions Set A

SECTION – A

1. A bunch of bytes stored in some storage device like hard-disk etc. is:
(A) File
(B) String
(C) Data
(D) Input stream

Answer

A

2. Which type of the following statements is true about a Python module?
(1) It is independent grouping of code and data.
(2) It can be reused in other programs.
(3) It depends on other modules.
(A) 1
(B) 1&3
(C) 2 & 3
(D) 1,2&3

Answer

B

3. Select the correct syntax for opening a file in Python
(A) < file-object > = open (<filename>)
(B) < file-object > = open (< filename >, < mode >)
(C) Both (A) & (B)
(D) Neither (A) nor (B)

Answer

C

4. A text file stores information in ……………. or …………….. characters.
(A) ASCII, ISCII
(B) Bits, English
(C) ASCII, Unicode
(D) Letters, Numeric

Answer

D

5. Identify the incorrect statement for opening text tile data.txt in read mode.
(A) F = open ( r “c:\data.txt”)
(B) F = open ( “c:\data.txt”,r )
(C) F = open ( “c:\data.txt”)
(D) F = open ( “c:\data.txt”, “r”)

Answer

C

6. ………………… is a named logical environment holding logical grouping of related objects
(A) Name space
(B) Module
(C) Function
(D) Doc string

Answer

A

7. Which of the following functions is a built-in function in Python?
(A) seed()
(B) sqrt()
(C) factorial()
(D) print()

Answer

D

8. ……………….. governs the type of operations possible in the opened file.
(A) File object
(B) File-mode
(C) File handle
(D) File( )

Answer

D

9. Operators that require only one operand to operate upon :
(A) Unary operators
(B) Binary operators
(C) Ternary operators
(D) Boolean operators.

Answer

A

10. Write a single statement equivalent to:
myobj=open(r1,“E:\poem.txt”, “r”)
mydata=myobj.read(38)
(A) open(“E:\\poem.txt”, “r”)
(B) open(r’E:\poem.txt’,read(38)
(C) file(“E:\\poem.txt”, “r”).read(38)
(D) file(r’E:\poem.txt’, “r”)

Answer

C

11. The string whose each character is 2 bytes long:
(A) All strings
(B) Triple quoted strings
(C) Multiline strings
(D) Unicode strings

Answer

D

12. The ‘r+’ mode will:
(A) Enable both reading and writing.
(B) Raise an error if the file doesn’t exist.
(C) Over write the already existing file.
(D) Both (A) & (B)

Answer

C

13. For the operator ‘+’, the valid pairs of operands will be :
(A) Hello, World
(B) 56, 89
(C) Hello, 56
(D) Both A & B.

Answer

A

14. import statement is used with, which type of python functions?
(A) Built in functions
(B) Functions defined in modules
(C) User defined functions
(D) All of these

Answer

C

15. sys.stdin.read( ) is used to read from:
(A) File named sys.stdin
(B) Keyboard
(C) File named stdin
(D) None of these

Answer

C

16. What is the scope of a variable declared in top level segment (– main –) of a program ?
(A) Global
(B) Local
(C) Depends on its used
(D) None of these.

Answer

C

17. 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

B

18. Consider the following code.
def sum ( a, b):                                        statement 1
s = a + b                                                   statement 2
return s                                                     statement 3
n1 = int (input (“Enter a number”))        statement 4
n2 = int (input (“Enter a number’))        statement 5
sum = sum (n1, n2)                                 statement 6
print (“sum=”, sum)                                statement 7
Choose the correct order of the execution of statements
(A) 1→2→3→4→5→6→7
(B) 1→2→3→4→5→7→6
(C) 6→7→1→2→3→4→5
(D) 4→5→6→1→2→3→7

Answer

C

19. Identify the incorrect form of import statement.
(A) from <module>import <object1>[,object2>,[…]]
(B) from <module> import <object>
(C) form <module> import all
(D) All of the above

Answer

D

20. …………………. are the variables that are listed within parentheses of a function header.
(A) Parameters
(B) Arguments
(C) Values
(D) None of these

Answer

D

21. ……………….. is a character that separates words or phrases in a line or record.
(A) Comma
(B) Tab
(C) Delimiter
(D) None of these

Answer

D

22. Identify the type of function statement from the syntax given below:
<function name> (<value – to – be – passed – to – argument>)
(A) Function header
(B) Function call
(C) Function definition
(D) None of these

Answer

C

23. A variable pointing to a value of a certain type can be made to point to a value an object of different type. This is called:
(A) Type Casting
(B) Coercion
(C) Dynamic Typing
(D) Assignment

Answer

D

24. Scope of a variables declared in a function body is
(A) Global
(B) Local
(C) Depends on function call
(D) None of these

Answer

B

25. Select the augmented assignment operator from the following.
(A) + =
(B) < >
(C) >>
(D) &.

Answer

C

SECTION – B

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

Answer

C

27. What will be the output of the following Python code snippet?
(A) 1 A 2 B 3 C
(B) 1 2 3
(C) A B C
(D) 1:”A” 2:”B” 3:”C”

Answer

D

28. Given a file “lines.txt” as shown below:
This is line 1
This is line 2
This is line 4
What would be the output of the following code?
file=open(“line.txt”)
f=file.readlines( )
print(f)
file.close( )
(A) [‘This is line1 \n‘, ‘This is line 2 \n‘, ‘\n’, ‘This is line 4’]
(B) [‘This is line1 \n‘, ‘This is line 2 \n‘, ‘This is line 4’]
(C) This is line1
This is line2
This is line4
(D) Syntax error

Answer

B

29. What will be the output of the following expression print (len (“covid-19”) / (len (‘2L’) + 2 * (–1) **3))
(A) 2
(B) Zero Division Error
(C) 0
(D) 56

Answer

B

30. What would be the output of the following line of code ?
f = open (r, “ c : /temp/data. txt”, “w”)
(A) A file data. txt will be opened in read & write mode.
(B) A file data. txt will be opened in write mode only if the file exists.
(C) A file data. txt will be opened in write mode, if it exists otherwise it would be created
(D) None of these

Answer

C

31. Identify the statements that would yield 2 as output.
(A) print (–5.0112)
(B) print (–5.0/2)
(C) print (5/2)
(D) print [(in) s.01/2]

Answer

D

32. Predict the output of (10 < 100) or (50 < 100/0)
(A) True
(B) False
(C) Division by zero error
(D) None of these

Answer

B

33. Consider a file myfile.txt as given below :
  This is the time of the year
  When the whole world around
  you is painted with colours
  of hues. It seems every mook
  and corner has been painted
  so beautifully by an expert artist.
What would be the output of the following code ?
  myfile = open (r’ myfile. txt’, “r”)
  str = myfile.read (30)
  print str
  myfile.close( )
(A) This will read first 30 characters from the file
(B) It will read first 30 bytes from the file and print them
(C) It will read the contents of the file 30 times
(D) It will place the file pointer at 30th character.

Answer

D

34. Predict the output
for a in 10, 12, 14, 16, 18 :
print(a)
(A) 10, 12, 14, 16, 18
(B) 10, 14, 16
(C) Syntax Error
(D) 10
12
14
16
18

Answer

B

35. Predict the output of the following code for a=5
def sumof3multiples1(n):
s=n*1+n*2+n*3
return s
a= int(input(“Enter a number”))
sumof3multiples1(a)
(A) 30
(B) 35
(C) No output will be shown
(D) None of these.

Answer

C

36. Consider a file “data. txt” containing following text.
I am line 1
I am line 2
I am the last one
Following code segment will produce the output :
F1 = open (“data.txt”, ‘r’)
Filetext = F1. readlines ( )
F1. close ( )
print (Filetext [–1])
(A) ‘e’
(B) I am the last one
(C) Syntax error
(D) None of these

Answer

D

37. Find the output of the below given code segment
when x = –2, 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 (“stream 1”),
elif x > y > z :
print (“stream 2”),
else :
print (“stream 3”),
print (“is selected for you”)
(A) stream 1 is selected for you
(B) stream 1 is selected for you
(C) stream 3 is selected for you
(D) stream 2 is selected for you

Answer

A

38. Predict the output of the below given code for a=2,b=3,c=9.
def myfunc(x,y,z):
s=x**3+y**2+z
return s
print (myfunc(a,b,c))
(A) 26
(B) 21
(C) 19
(D) None of these

Answer

A

39. Analyse the following code and predict what it is meant for?
longest = “ ”
for l in file (“abc. txt”).readlines ( ) :
if len (l > len (longest)):
longest = l
(A) It will search for the longest word in file
(B) It will search for the longest line in file
(C) It will find length of the longest word in file
(D) It will find length of the longest line in file

Answer

B

40. Consider the following program code :
str_dividend = input (“Enter dividend”)
str_divisor = input (“Enter divisor”)
int_dividend = int (str_dividend)
int_divisor = int (str_divisor)
if int_divisor = = 0 :
print “Division by zero not possible”
if int_divisor ! = 0;
print (str_dividend, “/”, str_divisor, “=”, int_dividend/int_divisor)
print (“Thank you”)
predict its output for input 45, 1
(A) 45
(B) 45.0
(C) Syntax Error
(D) None of these

Answer

B

41. Predict the output of the following code:
def CtoF(c):
temp =c/5.0*9+32
return temp
temp = CtoF (25)
print (temp)
(A) 77.0
(B) 32.55
(C) Error
(D) None of these

Answer

A

42. 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

B

43. Predict the output of the given code.
if not 5 :
print (“Smart/n”)
print (“Quick”)
(A) Smart
(B) Smart
(C) Smart Quick
(D) Quick

Answer

C

44. Predict the flow of execution of the following code:
def sum(a,b):                          ……-> 1
return(a+b)                             ……-> 2
print (sum(2,3)-sum(4,5))     ……-> 3
(A) 1->3->2->3->2->3
(B) 3->-1->2
(C) 3->2->3
(D) 1->2->3

Answer

B

45. What is the output of the following code ?
f=open(“Myfile.txt”, ‘r’)
s=f.readline( ).split( )
If the line “Myfile. txt” contains the year 2020 brought with it what no one would have imagined.”
(A) [The’, ‘year’, ‘2020’, ‘brought’, ‘with’, ‘it’.]
(B) What no one would have imagined
(C) [‘The’, ‘year’, ‘2020’, ‘brought’, ‘with’, ‘it’, ‘what’, ‘no’, ‘one’, ‘would’, ‘have’, ‘imagined’]
(D) syntax error

Answer

D

46. Predict the output of the below given code
def func(x,y)
return (x*y)
a,b=5,10
print(func(a,b))
(A) 50
(B) Nothing will be shown
(C) Syntax error
(D) None of these

Answer

D

47. (“hello”) == 25/5 or 20/10. Predict the output.
(A) True
(B) False
(C) Error
(D) None of these

Answer

A

48. 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

A

49. Predict the output:
for k in range (7,2):
print k
(A) 7




(B) 7
5
4
3
2
(C) 2
3
4
5
6
7
(D) Nothing will be shown

Answer

D

SECTION – C

CASE STUDY BASED QUESTIONS

This section consists of 6 Questions (50-55) Attempt any 5 questions.
I. Karan wrote a program to check whether a number is palindrome or not. Help him to complete
code for successfully run.
num=____ (input(“Enter a number:”))   #Statement 1
temp=num
rev=____                                             #Statement 2
while(num __ 0):                                  #Statement 3
dig=num% ____                                  #Statement 4
rev=rev*10+dig
num= _______                                    #Statement 5
if(temp==rev):
print(“The number is palindrome!”)
_____                                                 #Statement 6
print(“Not a palindrome!”)

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

A

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) <
(B) >
(C) ==
(D) !=

Answer

A

53. Choose the correct option to fill up the blank in line marked as Statement 4.
(A) 100
(B) 2
(C) 10
(D) 20

Answer

C

54. Choose the correct option to fill up the blank in line marked as Statement 5.
(A) num//10
(B) num*10
(C) num/10
(D) num+10

Answer

C

55. Choose the correct option to fill up the blank in line marked as Statement 6.
(A) else
(B) elif
(C) else:
(D) elif:

Answer

D