Class 12 Computer Science Sample Paper

Sample Papers for Class 12

Please refer to the Class 12 Computer Science Sample Paper below. These CBSE Sample Papers for Class 12 Computer Science have been prepared based on the latest guidelines and examination patterns issued for the current academic year. We have provided Term 1 and Term 2 sample papers with solutions. You can click on the links below and access the free latest CBSE Sample Papers for Computer Science for Standard 12. All guess papers for Computer Science Class 12 have been prepared by expert teachers. You will be able to understand the type of questions which are expected to come in the examinations and get better marks.

CBSE Sample Papers for Class 12 Computer Science

Class 12 Computer Science Sample Paper With Solutions Set A
Term 1 Sample Papers
Class 12 Computer Science Sample Paper Term 1 With Solutions Set A
Class 12 Computer Science Sample Paper Term 1 With Solutions Set B
Class 12 Computer Science Sample Paper Term 1 With Solutions Set C
Term 2 Sample Papers
Class 12 Computer Science Sample Paper Term 2 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

Question. Which of the following file open modes does not create a new file when the specified file has not yet been created?       
(a) a
(b) w+
(c) ab+
(d) r

Answer

D

Question. Consider a tuple T1=(18,12,11,13,15,16,18,11,10)     
What will be the output of the following code?
t=T1[3:].index(11)
print(t)

(a) 2
(b) 7
(c) 4
(d) 8

Answer

C

Question. Which of the following statements can open the file “C:\documents\mydiary.txt” in append mode?       
(a) File=open(“C:\\documents\\mydiary.txt”,’a’)
(b) with open(“C:\\documents\\mydiary.txt”,’a’) as File:
(c) File=open(“mydiary.txt”)
(d) with open(“C:\documents\mydiary.txt”,’a’) as File:
(a) Only (a)
(b) Only (b)
(c) Both (a) and(b)
(d) Both (a) and (d)

Answer

C

Question. Which of the following groups of functions belongs to pickle module?       
(a) reader(), writer()
(b) dump(), load()
(c) writerow(), read()
(d) writer(), readline()

Answer

B

Question. Identify which module is used to read/write data from/in the binary file?       
(a) csv
(b) random
(c) pickle
(d) numpy

Answer

C

Question. What is the output of the following code?
def stringfun(st):
c=0
st1=”
for i in range(1,len(st)):
if i%2==0:
st1=st1+str(a)
elif st[i].lower():
st1=st1+st[i-1]
else:
st1=st1+st[i]
print(‘-‘.join(st1))
stringfun(‘The Matrix 4’)
(a) T-2-e-4-M-6-t-8-i-1-0-
(b) 2-T-e-4-M-e-6-r-8-i-1-0-
(c) 0-T-e-4-M-6-t-8-i-1-0-
(d) T-2-h-4-e-6-M-8-a-1-0-t-

Answer

A

Question. Identify the incorrect declaration of assigning values to variables.         
(a) a, b, c =[1,2,3],(a,b,c),’d’
(b) x, y, z = 1, ‘Red’, 2+3
(c) p q r = 20,30,40
(d) length, width = 9*8, 40/4

Answer

C

Question. Identify the correct statement regarding relative path of a file.           
(a) The relative paths are from the root (top) level of the directory structure.
(b) The relative path includes only the file name if the file is stored in root directory.
(c) The relative paths are relative to current working directory.
(d) If the file is in current working directory, then it is denoted with two dots(..) in the file path.

Answer

C

Question. Consider the content of the file ‘Story.txt’:         
The Tortoise meanwhile kept going slowly but steadily and, after a time, passed the place where the Hare was sleeping. But the Hare slept on very peacefully; and when at last he did wake up, the Tortoise was near the goal. The Hare now ran his swiftest, but he could not overtake the Tortoise in time.
What is the output of the following code?
Fileobj = open(“story.txt”, ‘r’)
S1= Fileobj.read(20)
S2= Fileobj.tell()
Fileobj.seek(34,0)
S3= Fileobj.read(20)
print(S3)
(a) The Tortoise meanwhi
(b) slowly but steadily
(c) Hare was sleeping
(d) he Tortoise in time

Answer

B

Question. Which of the following statement is considered as inline comment?           
# This is my first program 
a,b=300,10 # The value of a is 300 and b is 10
b=a
a=b+100
‘’’Here the value of b is now 300 and the value of a is the value of b increased by 100’’’  print(a,b)
# Printing the value of a and b 
(a) Statement 1
(b) Statement 2
(c) Statement 3
(d) Statement 4

Answer

B

Question. Consider a function header:           
def Count_Total(Itemname,Cost,Qty,Disc=0.25):
Which of the following function calls is valid to invoke the given function definition?
(a) Count_Total(10, Itemname= ‘Shirt’, 1000.0)
(b) Count_Total(‘Shirt’, Cost = 1500, Qty =2, Disc =0.30)
(c) Count_Total(‘Shirt’, 1000.0)
(d) Count_Total(10, ‘Shirt’, Disc=0.25, 1000.0)

Answer

B

Question. Which statement consists of a logical operator?     
(a) a+b**c
(b) a >b:
(c) a and b not c
(d) 2 in a

Answer

C

Question. Which of the following file formats does not have an EOL character?         
(a) Text file
(b) Binary file
(c) CSV file
(d) None of the above

Answer

B

Question. Suppose content of ‘myquote.txt’ file is The secret of getting ahead is getting started.         
What will be the output of the following code?
file = open(“myquote.txt”, ‘r’)
txt = file.read()
a=txt.split()
print(len(a))
(a) 9
(b) 7
(c) 8
(d) 10

Answer

C

Question. Consider a code:         
Fileobj = open(“story.txt”, ‘a’)
x= 200
a= Fileobj.write(x)
Fileobj.close()
What is the output of the above given code?
(a) Generates an error : x must be string
(b) It will write 200 at the end of the file.
(c) It will write 200 at the beginning of the file.
(d) It will delete the existing content and write 200 in the beginning.

Answer

A

Question. What will be the output of the following code?           
import math
def display(x):
a= sqrt(x)
print(a)
i = 144
display(a)
(a) 12.0
(b) 12
(c) Error
(d) 72

Answer

C

Question. Consider the statements given below:           
import pickle
Tup1=(‘Pen’,’Pencil’,’Eraser’,’Notebook’)
with open(‘Mybag.dat’, ‘wb’) as binfile:
——————— #Statement1
Identify the missing code in Statement 1 that will write data from a list on the binary file.
(a) pickle.load(mybinfile, Tup1)
(b) pickle.dump(mybinfile, Tup1)
(c) pickle.dump(Tup1, binfile)
(d) pickle.load(Tup1, binfile)

Answer

C

Question. When we open a file using this method, we ensure that all of the resources assigned to the file objects are automatically deallocated when we stop using the file. Identify the method in the above lines.           
(a) close()
(b) open()
(c) with open()
(d) open with()

Answer

C

Question. Consider a file “online.txt”         
With educational institutes closed due to the COVID-19 pandemic, the government has been encouraging online education to achieve academic continuity.
Online education allows for learning something beyond the norm.
What will be the output of the following code?
fileobj=open(‘online.txt’,’r’)
count = 0
l=fileobj.readline()
for i in l:
if ‘o’ in i:
count=count+1
print(count)
fileobj.close()
(a) 10
(b) 8
(c) 9
(d) 20

Answer

C

Question. Consider a code:         
f=open(“song.txt”,’r’)
a=f.________
print(type(a))
Output: <class ‘list’>
Fill in the blanks with the appropriate function that will produce the output shown above.
(a) read()
(b) readlines()
(c) read(10)
(d) readline()

Answer

B

Question. Assume you are reading from a text file from the beginning and you have read 10 characters. Now you want to start reading from the 50th character from the beginning. Which function will you use to do the same?       
(a) seek(50,1)
(b) seek(50,2)
(c) seek(40,0)
(d) seek(50,0)

Answer

D

Question. Fill in the blanks with the appropriate function to get the desired output.         
a= _______(11/3)
print(a)
Output: 3
(a) float
(b) str
(c) list
(d) int

Answer

D

Question. Identify the output of the following Python statements.         
L1=[6,4,2,9,7]
L1[3:]= “100”
(a) [6,4,2,9,7,100]
(b) [6,4,2,100]
(c) [6,4,2,1,0,0]
(d) [6,4,2, ‘1’,’0’,’0’]

Answer

D

Question. Identify the incorrect statement regarding local and global variables.         
(a) Local variables cannot be accessed outside the function.
(b) If a local variable exists with the same name as the global, then global variable is shadowed.
(c) Global variables can be accessed in any function using global keyword.
(d) The lifetime of the local variable is the entire program run.

Answer

D

Question. What is the output of the following code snippet?         
def flipnumber(L1,L2,L3):
for i in range(0,4):
L3.append(L1[i]+L2[i])
print(L3)
L1=[i for i in range(0,4)]
L2=[j for j in range(2,6)]
L3=[]
ListAdd(L1,L2,L3)
(a) [0,2,3,4]
(b) [1,2,3,4]
(c) [11,22,33,44]
(d) [2, 4, 6, 8]

Answer

D

Question. What will be the output of the following code snippet?         
Tup1=(10,20,(7,8,9),50)
t=list(Tup1)
print(t)
print(max(t[2]))
(a) [10, 20, (7, 8, 9), 50] /9
(b) [[10, 20, [7, 8, 9], 50]/ 50
(c) [10, 20, 7, 8, 9, 50]/ 50
(d) ([10, 20, 50])/ 50 

Answer

A

Question. Identify the output of the following Python statements.           
x=1
while x<5:
if x%3==0:
print(x*2,end=”)
else:
print(x,end=”)
x=x+1
(a) 1234
(b) 1264
(c) 2364
(d) 3364

Answer

B

Question. Identify the output of the following Python statements.     
for i in range(0,10,2):
if i%2==0:
a=i**2
print(a,end=’#’)
(a) 2#4#6#8#10#
(b) 0#4#16#36#64
(c) 1#2#3#4#5#
(d) 0#1#2#3#4#5

Answer

B

Question. What will be the output of the following code?       
p=10
def power():
global p
q=2
p=p**q
return p
print(p)
power()
print(p)
(a) 10/200
(b) 10/100
(c) 100/10
(d) 10/10

Answer

B

Question. Write the output of the following Python statements:         
L1 = [12,32,42,34,54,65]
L2=[87,98,67,90]
L2.pop(1)
L1.extend(L2)
L1.insert(5,100)
print(max(L1[2:9:2]))
(a) 100
(b) 42
(c) 87
(d) 67

Answer

D

Question. Given a tuple A = (10,12,14,16,18) Identify the statement from the list below that will add 17 at the end of the existing elements.   
(a) A += (17,)
(b) A = (17,)
(c) A = A+17
(d) A += 17

Answer

A

Question. Which of the following operators can be used to replicate two strings?         
(a) +
(b) –
(c) *
(d) //

Answer

C

Question. Soumya is learning to use word processing software for the first time. She creates a file with some text formatting features using notepad. What type of file is she working on?   
(a) Text file
(b) CSV file
(c) Binary file
(d) All of the above

Answer

A

Question. Given a tuple T1=(4,3,7,9,7,6,5) What will be the output of the following code?       
print(T1[-7],T1[-3]*3)
(a) 4, 7 7 7
(b) 4 21
(c) -5 -7
(d) 4 –21 

Answer

B

Question. Consider a CSV file and a code:   

CBSE Sample Papers for Class 12 Computer Science Term 1 - Set 1

import csv
with open(‘myfile.csv’,’r’) as csv_file:
reader=csv.reader(csv_file)
rows=[]
value=0
for i in reader:
if ____________________: continue
rows.append(a)
value=len(list(reader))
print(value)
Identify the suitable code in line marked as Statement1 that will exclude the header and count exact
number of records.
(a) reader.line_num==0
(b) csv_file.line_num==1
(c) reader.line_num==0
(d) reader.exclude_header

Answer

A

Question. Identify the incorrect statement regarding declaration of function header.           
(a) def Tot_Marks (T1, T2, Total = 100):
(b) def Tot_Marks (T1 = x, T2 = y, Total = z):
(c) def Tot_Marks (T1, T2, Total):
(d) def Tot_Marks (T1 = 200, T2 = 250, Total = 600):

Answer

B

Question. Consider a function declaration           
def Product(a,b):
return a*b
Product(10,12)
Which statement is correct regarding actual argument and formal argument?
(a) Formal argument: a,b and Actual argument: 10,12
(b) Formal argument 10,12 and Formal argument: a,b
(c) Both are actual arguments
(d) Formal argument: a, 10 and actual argument: b, 12

Answer

A

Question. Identify the correct statement.           
(a) List can be used as keys of dictionary.
(b) Tuples can be used as keys of dictionary, if they contain only strings, numbers or tuples.
(c) Lists, like strings are immutable.
(d) Performing list(dict) on a dictionary returns a list of all the values used in the dictionary.

Answer

B

Question. Evaluate the following expression and identify the correct answer:           
import math
a= math.pow(3,3)+round(48.7) – math.floor(4.09)
(a) 80.0
(b) 72.0
(c) 70.0
(d) 60.0

Answer

B

Question. Consider the content of ‘smile.txt’ file:       
the greatest self is a peaceful smile, that always sees the world smiling back.
What will be the output of the following code?
f=open(“smile.txt”,’r’)
c=0
x=f.read()
l=x[0:20]
for i in range(len(l)):
if x[i] not in (‘aeiou’):
c+=1
print(c)
f.close()
(a) 14
(b) 11
(c) 10
(d) 5

Answer

C

Question. Consider the given code and identify the incorrect output.           
import random
no1=random.randint(0,5)
print(no1,end=’#’)
no2= random.randint(3,5)
print(no2,end=’#’)
no3=random.randint(2,5)
print(no3)
(a) 0#0#1
(b) 2#5#5
(c) 8#0#1
(d) 5#3#2

Answer

C

Question. Identify the incorrect statement regarding a tuple tup1.tup1 =(1,2,3,4,5,6)       
(a) len(tup1)
(b) sorted(tup1)
(c) 4 in tup1
(d) Tup1+(10)

Answer

D

Question. Consider a file ‘rhyme.txt’ Power to Empower. What will be the output of the following code?             
fileobj = open(‘forest.txt’, ‘r’)
R1 = (fileobj.readline().split())
for word in R1:
for ch in range(len(word)-1,-1,-1):
print(word[ch],end=”)
print(end=”)
fileobj.close()
(a) rewoPot.rewopmE
(b) .rewopmE rewoPot
(c) Empower. to Power
(d) Power Empower. to

Answer

A

Question. What will be the contents of the ‘mylist.dat’ file after executing the following code?         
import pickle
lst1,lst2=[80,20,31,92,67,81,63][]
for i in lst1:
if(i%2==0 and i%5==0):
lst2.append(a)
f=open(“mylist.dat”,’wb’)
data=pickle.dump(lst2,f)
f.close()
(a) 31/92
(b) 80/20
(c) 67/97
(d) 63/20   

Answer

B

Question. What will be the output of the following code?     
t=(1,2,3,4,5,6)
def add(A):
A[0]=A[0]**2
A[1]+=5
return A
b=add(t)
print(b)
(a) (1,7,3,4,5,6)
(b) (1,1,12,3,4,5,6)
(c) (1,7,5,6,7,8)
(d) Error

Answer

D

Question. Suppose the content of ‘Python.txt’ is:     
Python is an easy to learn, powerful programming language. It has efficient
high-level data structures and a simple but effective approach to objectoriented programming.
What will be the output of the following code?
file = open(‘Python.txt’,’r’)
line = file.read()
word = line.split()
count=0
for w in word:
if len(w)>5:
count+=1
print(count)
file.close()
(a) 12
(b) 13
(c) 10
(d) 15

Answer

B

Question. Which of the following functions forces the writing of data on disc which is still pending in the output buffer?         
(a) read()
(b) save()
(c) flush()
(d) load()

Answer

C

Question. Consider the content of ‘rhyme.txt’ file:         
Here we go round the mulberry bush,
The mulberry bush,
The mulberry bush.
Here we go round the mulberry bush
On a cold and frosty morning.
What will be the output of the following code?
fileobj=open(‘rhyme.txt’,’r’)
count = 0
l=fileobj.readlines()
for i in l:
if(i[0]==’H’or i[0]==’T’):
count=count+1
print(count)
fileobj.close()
(a) 4
(b) 2
(c) 3
(d) 1

Answer

A

Question. While creating writer object of csv file, what is the significance of delimiter argument if not specified?       
(a) Semicolon is used to separate the values.
(b) Comma is used to separate the values.
(c) Pipe symbol is used to separate the values.
(d) Colon is used to separate the values.

Answer

B

Case Study Based Questions

The owners of the ‘Foodmill’ store wish to generate a bill for each transaction using a binary file. In order to do this, they have recruited a friend who is learning Python. The friend has made a file called ‘foodmill.dat’ that contains information like Itemno, Item Name, Qty and Price in order to compute Total Amount, but is having problems finishing it. Assist the friend in finishing the code.     
Incomplete Code:
import ________ 
File = _____(‘foodmill.dat’,’_____’) 
ch=’y’
while True:     
Itemno = input(“Enter Item No:”)
Product = input(“Enter Product Name:”)
Qty= int(input(“Enter Quantity:”))
Price = int(input(“Enter Price:”))
Amount=Qty *Price
records= [Itemno,Product,Qty,Price,Amount]
pickle.______________ 
ch=input(“Do you want to buy more….”)
if ch==’y’ or ch==’Y’:
continue   
else:
break
File.close()
def Total_Amount():
f= open(‘foodmill.dat’,’rb+’)
total_Amt=0
try:
while True:
R=_________ 
___________________ 
print(“You have purchased”,R[2],R[1],”of
price”,”Rs”,R[3],”and amount is”, R[4])
____________: 
f.close()
print(“Total Amount is Rs”,total_Amt)

Question. Identify the suitable code to calculate the total Amount in the line marked as Statement 5.       
(a) total_Amt=R[4]
(b) total_Amt=R[3]+R[4]
(c) total_Amt+=R[4]
(d) total_Amt=R[4]*2

Answer

C

Question. Identify the suitable code for blank space in the line marked as Statement 3.         
(a) load(records,file)
(b) dumps(record,file)
(c) dump(records,file)
(d) load(file,records)

Answer

C

Question. Identify the relevant module to import in the blank space in line marked as Statement 1.       
(a) pickle
(b) bin
(c) tsv
(d) csv

Answer

A

Question. Identify the code to open the file along with the access mode so that every time the program is run, new customer records will be added in Statement 2.     
(a) open ‘rb’
(b) open ‘wb’
(c) open ‘r’
(d) write ‘w’

Answer

B

Question. Identify the suitable code for blank space in line marked as Statement 4.           
(a) pickle.load(F)
(b) pickle.dump(f)
(c) pickle.load(R)
(d) pickle.load(f)

Answer

D

Question. Identify the suitable keyword to handle the exception (if any) that occurs during execution of the try clause.         
(a) catch
(b) except
(c) stop
(d) exception 

Answer

B

Class 12 Computer Science Sample Paper