Please refer to Class 12 Computer Science Sample Paper with solutions provided below. All sample papers for Computer Science Class 12 have been designed as per the latest paper pattern issued by CBSE for the current academic year. Students should practice these guess papers for Class 12 Computer Science as it will help them to gain more understanding of the type of questions that are expected to be asked in upcoming Class 12 Computer Science exams. Please click on the links below to access free CBSE Sample Papers for Class 12 Computer Science.
Class 12 Computer Science Sample Paper Term 1 Set A
SECTION – A
This section consists of 25 Questions (1 to 25). Attempt any 20 questions from this section. Choose the best possible option.
1. Find the invalid identifier from the following:
(A) none
(B) address
(C) Name
(D) pass
Answer
D
2. Consider a declaration L = (1, ‘Python’, ‘3.14’).
Which of the following represents the data type of L?
(A) list
(B) tuple
(C) dictionary
(D) string
Answer
B
3. Given a tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output to print (tup1 [3:7:2])?
(A) (40,50,60,70,80)
(B) (40,50,60,70)
(C) [40,60]
(D) (40,60)
Answer
D
4. Which of the following option is not correct?
(A) if we try to read a text file that does not exist, an error occurs.
(B) if we try to read a text file that does not exist, the file gets created.
(C) if we try to write on a text file that does not exist, no error occurs.
(D) if we try to write on a text file that does not exist, the file gets created.
Answer
B
5. Which of the following options can be used to read the first line of a text file “Myfile.txt”?
(A) myfile = open(‘Myfile.txt’); myfile.read()
(B) myfile = open(‘Myfile.txt’,’r’); myfile.read(n)
(C) myfile = open(‘Myfile.txt’); myfile.readline()
(D) myfile = open(‘Myfile.txt’); myfile.readlines()
Answer
C
6. Assume that the position of the file pointer is at the beginning of 3rd line in a text file. Which of the following option can be used to read all the remaining lines?
(A) myfile.read()
(B) myfile.read(n)
(C) myfile.readline()
(D) myfile.readlines()
Answer
D
7. A text file “student.txt” is stored in the storage device. Identify the correct option to open the file in read mode.
(i) myfile = open(‘student.txt’,’r+’)
(ii) myfile = open(‘student.txt’,’w’)
(iii) myfile = open(‘student.txt’,’r’)
(iv) myfile = open(‘student.txt’)
(A) only (i)
(B) both (i) and (iv)
(C) both (iii) and (iv)
(D) both (i) and (iii)
Answer
C
8. The return type of the input() function is
(A) string
(B) integer
(C) list
(D) tuple
Answer
A
9. Which of the following operator cannot be used with string data type?
(A) +
(B) in
(C) *
(D) /
Answer
D
10. Consider a tuple tup1 = (10, 15, 25, 30). Identify the statement that will result in an error.
(A) print(tup1[2])
(B) tup1[2] = 20
(C) print(min(tup1))
(D) print(len(tup1))
Answer
B
11. Which of the following statement is incorrect in the context of binary files?
(A) Information is stored in the same format in which the information is held in memory.
(B) No character translation takes place.
(C) Every line ends with a new line character.
(D) pickle module is used for reading and writing.
Answer
C
12. What is the significance of the tell() method?
(A) tells the path of file.
(B) tells the current position of the file pointer within the file.
(C) tells the end position within the file.
(D) checks the existence of a file at the desired location.
Answer
B
13. Which of the following statement is true?
(A) pickling creates an object from a sequence of bytes.
(B) pickling is used for object serialization.
(C) pickling is used for object deserialization.
(D) pickling is used to manage all types of files in Python.
Answer
B
14. Syntax of seek function in Python is myfile.seek(offset, reference_point) where myfile is the file object. What is the default value of reference_point?
(A) 0
(B) 1
(C) 2
(D) 3
Answer
A
15. Which of the following components are parts of a function header in Python?
(i) Function Name
(ii) Return Statement
(iii) Parameter List
(iv) def keyword
(A) Only (i)
(B) (i) and (ii)
(C) (iii) and (iv)
(D) (i), (ii) and (iv)
Answer
D
16. Which of the following function header is correct?
(A) def cal_si(p=100, r, t=2)
(B) def cal_si(p=100, r=8, t)
(C) def cal_si(p, r=8, t)
(D) def cal_si(p, r=8, t=2)
Answer
D
17. Which of the following is the correct way to call a function?
(A) my_func()
(B) def my_func()
(C) return my_func
(D) call my_func()
Answer
A
18. Which of the following character acts as default delimiter in a CSV file?
(A) (colon) :
(B) (hyphen) –
(C) (comma) ,
(D) (vertical line) |
Answer
C
19. Syntax for opening “Student.csv” file in write mode is myfile = open(“Student.csv”,”w”,newline=’ ’). What is the importance of newline=’’?
(A) A newline gets added to the file.
(B) Empty string gets appended to the first line.
(C) Empty string gets appended to all lines.
(D) EOL translation is suppressed.
Answer
D
20. Consider the following Python program
import csv
fh=open (“student.csv”, “r”)
stureader=csv.reader(fh)
for rec in stureader:
print(rec)
What will be the data type of rec?
(A) string
(B) list
(C) tuple
(D) dictionary
Answer
B
21. Which of the following is not a function / method of csv module in Python?
(A) read()
(B) reader()
(C) writer()
(D) writerow()
Answer
A
22. Which one of the following is the default extension of a Python file?
(A) .exe
(B) .p++
(C) .py
(D) .p
Answer
C
23. Which of the following symbol is used in Python for single line comment?
(A) /
(B) /*
(C) //
(D) #
Answer
D
24. Which of the following statement opens a binary file “record.bin” in write mode and writes data from a list lst1 = [1,2,3,4] on the binary file?
(A) with open(‘record.bin’,’wb’) as myfile:
pickle.dump(lst1,myfile)
(B) with open(‘record.bin’,’wb’) as myfile:
pickle.dump(myfile,lst1)
(C) with open(‘record.bin’,’wb+’) as myfile:
pickle.dump(myfile,lst1)
(D) with open(‘record.bin’,’ab’) as myfile:
pickle.dump(myfile,lst1)
Answer
A
25. Which of these about a dictionary is false?
(A) The values of a dictionary can be accessed using keys.
(B) The keys of a dictionary can be accessed using values.
(C) Dictionaries aren’t ordered.
(D) Dictionaries are mutable.
Answer
B
SECTION – B
This section consists of 24 Questions (26 to 49). Attempt any 20 questions.
26. What is the output of following code:
T=(100)
print(T*2)
(A) Syntax error
(B) (200)
(C) 200
(D) (100,100)
Answer
C
27. The content of ‘Myfile.txt’ is:
Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky
What will be the output of the following code?
myfile = open(“Myfile.txt”)
data = myfile.readlines()
print(len(data))
myfile.close()
(A) 3
(B) 4
(C) 5
(D) 6
Answer
B
28. What is the output of the following Python statements.
x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
(A) 12.0
(B) 13.0
(C) 14.0
(D) 15.0
Answer
D
29. What is the output of the following Python statements.
x = 2
while x < 9:
print(x, end=’’)
x = x + 1
(A) 12345678
(B) 123456789
(C) 2345678
(D) 23456789
Answer
C
30. What is the output of the following Python statements.
b = 1
for a in range(1, 10, 2):
b += a + 2
print(b)
(A) 31
(B) 33
(C) 36
(D) 39
Answer
C
31. What is the output of the following Python statements.
lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
(A) 2
(B) 3
(C) 4
(D) 20
Answer
B
32. Raghav is trying to write a tuple tup1 = (1,2,3,4,5) on a binary file “test.bin”. Consider the following code written by him.
import pickle
tup1 = (1,2,3,4,5)
myfile = open(“test.bin”,’wb’)
pickle._______ #Statement 1
myfile.close()
Identify the missing code in Statement 1.
(A) dump(myfile,tup1)
(B) dump(tup1, myfile)
(C) write(tup1,myfile)
(D) load(myfile,tup1)
Answer
B
33. A binary file “employee.dat” has following data:

def display(eno):
f=open(“employee.dat”,”rb”)
totSum=0
try:
while True:
R=pickle.load(f)
if R[0]==eno:
__________ #Line1
totSum=totSum+R[2]
except:
f.close()
print(totSum)
When the above mentioned function, display (103) is executed, the output displayed is 190000. Write appropriate jump statement from the following to obtain the above output.
(A) jump
(B) break
(C) continue
(D) return
Answer
C
34. What will be the output of the following Python code?
def add (num1, num2):
sum = num1 + num2
sum = add(20,30)
print(sum)
(A) 50
(B) 0
(C) Null
(D) None
Answer
D
35. Evaluate the following expression and identify the correct answer.
16 – (4 + 2) * 5 + 2**3 * 4
(A) 54
(B) 46
(C) 18
(D) 32
Answer
C
36. What will be the output of the following code?
def my_func(var1=100, var2=200):
var1+=10
var2 = var2 – 10
return var1+var2
print(my_func(50),my_func())
(A) 100 200
(B) 150 300
(C) 250 75
(D) 250 300
Answer
D
37. What will be the output of the following code?
value = 50
def display(N):
global value
value = 25
if N%7==0:
value = value + N
else:
value = value – N
print(value, end=”#”)
display(20)
print(value)
(A) 50#50
(B) 50#5
(C) 50#30
(D) 5#50#
Answer
B
38. What will be the output of the following code?
import random
List=[“Delhi”,”Mumbai”,”Chennai”,”Kolkata”]
for y in range(4):
x = random.randint(1,3)
print(List[x],end=”#”)
(A) Delhi#Mumbai#Chennai#Kolkata#
(B) Mumbai#Chennai#Kolkata#Mumbai#
(C) Mumbai# Mumbai #Mumbai # Delhi#
(D) Mumbai# Mumbai #Chennai # Mumbai
Answer
B
39. What is the output of the following code?
def ChangeVal(M,N):
for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3
L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end=”#”)
(A) 5#8#15#4#
(B) 5#8#5#4#
(C) 5#8#15#14#
(D) 5#18#15#4#
Answer
B
40. The content of ‘Myfile.txt’ is
Humpty Dumpty sat on a wall
Humpty Dumpty had a great fall
All the king’s horses and all the king’s men
Couldn’t put Humpty together again
What will be the output of the following code?
myfile = open(“Myfile.txt”)
record = myfile.read().split()
print(len(record))
myfile.close()
(A) 24
(B) 25
(C) 26
(D) 27
Answer
C
41. Find the output of the following code:
Name=”PythoN3a.1”
R=””
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+”#”
print(R)
(A) pYTHOn##@
(B) pYTHOnN#@
(C) pYTHOn#@
(D) pYTHOnN@#
Answer
B
42. The content of ‘Myfile.txt’ is: Honesty is the best policy.
What will be the output of the following code?
myfile = open(“Myfile.txt”)
x = myfile.read()
print(len(x))
myfile.close()
(A) 5
(B) 25
(C) 26
(D) 27
Answer
D
43. The content of ‘Myfile.txt’ is:
Humpty DUMPTY sat on a wall
Humpty DUMPTY had a great fall
All the King’s horses and all the King’s men
Couldn’t put Humpty together again
What will be the output of the following code?
myfile = open(“Myfile.txt”)
x = myfile.read().lower()
y = x.count(‘umpty’)
print(y)
myfile.close()
(A) 2
(B) 3
(C) 4
(D) 5
Answer
D
44. What will be the output of the following code?
x = 3
def myfunc():
global x
x+=2
print(x, end=’ ‘)
print(x, end=’ ‘)
myfunc()
print(x, end=’ ‘)
(A) 3 3 3
(B) 3 4 5
(C) 3 3 5
(D) 3 5 5
Answer
D
45. The content of ‘Myfile.txt’ is: Ek Bharat Shreshtha Bharat
What will be the output of the following code?
myfile = open(“Myfile.txt”)
vlist = list(“aeiouAEIOU”)
vc=0
x = myfile.read()
for y in x:
if(y in vlist):
vc+=1
print(vc)
myfile.close()
(A) 6
(B) 7
(C) 8
(D) 9
Answer
B
46. The content of ‘Myfile.txt’ is:
Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky
Twinkle twinkle little star
What will be the output of the following code?
myfile = open(“Myfile.txt”)
line_count = 0
data = myfile.readlines()
for line in data:
if line[0] == ‘T’:
line_count += 1
print(line_count)
myfile.close()
(A) 2
(B) 3
(C) 4
(D) 5
Answer
A
47. Consider the following directory structure.

Suppose root directory (School) and present working directory are the same. What will be the absolute path of the file “Syllabus.jpg”?
(A) School/Syllabus.jpg
(B) School/Academics/Syllabus.jpg
(C) School/Academics/../Syllabus.jpg
(D) School/Examination/Syllabus.jpg
Answer
B
48. The content of text file, ‘student.txt’ is:
Arjun Kumar
Ismail Khan
Joseph B
Hanika Kiran
What will be the data type of data_rec?
myfile = open(“Myfile.txt”)
data_rec = myfile.readlines()
myfile.close()
(A) string
(B) list
(C) tuple
(D) dictionary
Answer
B
49. What will be the output of the following code?
tup1 = (1,2,[1,2],3)
tup1[2][1]=3.14
print(tup1)
(A) (1,2,[3.14,2],3)
(B) (1,2,[1,3.14],3)
(C) (1,2,[1,2],3.14)
(D) Error Message
Answer
B
SECTION – C
CASE STUDY BASED QUESTIONS
This section consists of 6 Questions (50 -55) Attempt any 5 questions.
Rohit, a student of class 12, is learning CSV File Module in Python. During examination, he has been assigned an incomplete python code (shown below) to create a CSV File ‘Student.csv’ (content shown below). Help him in completing the code which creates the desired CSV File.
CSV File
1. AKSHAY, XII, A
2. ABHISHEK, XII, A
3. ARVIND, XII, A
4. RAVI, XII, A
5. ASHISH, XII, A
Incomplete Code
import _____ #Statement-1
fh = open(_____, _____, newline=’’) #Statement-2
stuwriter = csv._____ #Statement-3
data = [ ]
header = [‘ROLL_NO’, ‘NAME’, ‘CLASS’, ‘SECTION’]
data.append(header)
for i in range(5):
roll_no = int(input(“Enter Roll Number : “))
name = input(“Enter Name : “)
Class = input(“Enter Class : “)
section = input(“Enter Section : “)
rec = [ _____ ] #Statement-4
data.append(_____) #Statement-5
stuwriter. _____ (data) #Statement-6
fh.close()
50. Identify the suitable code for blank space in the line marked as Statement-1.
(A) csv file
(B) CSV
(C) csv
(D) cvs
Answer
C
51. Identify the missing code for blank space in line marked as Statement-2.
(A) “Student.csv”,”wb”
(B) “Student.csv”,”w”
(C) “Student.csv”,”r”
(D) “Student.cvs”,”r”
Answer
B
52. Choose the function name (with argument) that should be used in the blank space of line marked as Statement-3.
(A) reader(fh)
(B) reader(MyFile)
(C) writer(fh)
(D) writer(MyFile)
Answer
C
53. Identify the suitable code for blank space in line marked as Statement-4.
(A) ‘ROLL_NO’, ‘NAME’, ‘CLASS’, ‘SECTION’
(B) ROLL_NO, NAME, CLASS, SECTION
(C) ‘roll_no’,’name’,’Class’,’section’
(D) roll_no,name,Class,section
Answer
D
54. Identify the suitable code for blank space in the line marked as Statement-5.
(A) data
(B) record
(C) rec
(D) insert
Answer
C
55. Choose the function name that should be used in the blank space of line marked as Statement-6 to create the desired CSV File?
(A) dump()
(B) load()
(C) writerows()
(D) writerow()
Answer
C
