Arihant Computer Science Class 12 Term 1 Sample Papers
Arihant Computer Science Class 12 Term 1 Sample Papers
me/cbseexamsweb
As per CBSE Sample Paper
Issued On 02 Sep, 2021...
Sample
Papers
Computer Science
CBSE Class 12 (Term I )
https://t.me/cbseexamsweb
As per CBSE Sample Paper
Issued On 02 Sep, 2021...
Sample
Papers
Computer Science
CBSE Class 12 (Term I )
Author
Neetu Gaikwad
https://t.me/cbseexamsweb
ARIHANT PRAKASHAN (School Division Series)
All Rights Reserved
© Publisher
Head Office
Kalindi, TP Nagar, Meerut (UP) - 250002, Tel: 0121-7156203, 7156204
Sales & Support Offices
Agra, Ahmedabad, Bengaluru, Bareilly, Chennai, Delhi, Guwahati,
Hyderabad, Jaipur, Jhansi, Kolkata, Lucknow, Nagpur & Pune.
ISBN : 978-93-25795-33-4
PO No : TXT-XX-XXXXXXX-X-XX
Published by Arihant Publications (India) Ltd.
For further information about the books published by Arihant, log on to
www.arihantbooks.com or e-mail at [email protected]
Follow us on
https://t.me/cbseexamsweb
Contents
þ One Day Revision 1-6
þ The Qualifiers 7-17
þ CBSE Question Bank 18-26
þ Latest CBSE Sample Paper 27-39
https://t.me/cbseexamsweb
Syllabus
Computer Science CBSE Class 12 (Term I )
Unit Periods
No. Unit Name Marks
Theory Practical
I. Computational Thinking and Programming -
TERM I
Unit I : Computational Thinking and Programming
l Revision of Python topics covered in Class XI.
l Functions: types of function built-in functions, functions defined in module, user defined
functions , creating user defined function, arguments and parameters, default parameters,
positional parameters, function returning value s , flow of execution, scope of a variable
global scope, local scope
l Introduction to files, types of files Text file, Binary file, CSV file , relative and absolute paths
l Text file: opening a text file, text file open modes r, r+, w, w+, a, a+ , closing a text file,
opening a file using with clause, writing appending data to a text file using write and
writelines , reading from a text file using read , readline and readlines , seek and tell
methods, manipulation of data in a text file
l Binary file: basic operations on a binary file: open using file open modes rb, rb+, wb, wb+, ab,
ab+ , close a binary file, import pickle module, dump and load method, read, write create,
search, append and update operations in a binary file
l CSV file: import csv module, open close csv file, write into a csv file using csv.writerow and
read from a csv file using csv.reader
https://t.me/cbseexamsweb
MCQs Preparation Tips
1. Read the paper from beginning to Step by step solution is not required
end & attempt those questions first in in MCQ type questions, it is a waste
which you are confident. Now move of time, you will not get extra marks
on to those questions which requires for this.
thinking and in last attempt those
4. Most of the time, you need not to
questions for which you need more
solve the MCQ completely to get the
attention.
correct option. You can start thinking
2. Read instructions of objective in reverse order and choose the best
questions carefully and find out what fit option.
is being asked, a bit carelessness can
5. As there is no negative marking for
lead you to incorrect answer.
incorrect answers, so don't leave any
3. Tick/Write down the correct option question unanswered. Use your
only while filling the OMR sheet. guess if you have not exact idea
about the correct answer.
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 01
ONE DAY
REVISION
Revise All the Concepts in a Day
Just Before the Examination...
https://t.me/cbseexamsweb
02 CBSE Sample Paper Computer Science Class XII (Term I)
10. Data Types Data type is a term that is used to ● if Statement This statement is used to decide
show the kind of data values or the type of data whether a certain statement or block of
that is expected to be handled. statements will be executed or not, i.e. if a
certain condition is True, then a block of
i.e. Data types are used to identify the type of data
statement is executed otherwise not.
and associated operations to handle it.
● if-else Statement This statement also tests a
There are different data types available in Python as conditional expression. If the condition is True,
the entire block of statements following the if
Integer will be executed. Otherwise, the entire block of
Numeric statements following the else will be executed.
Type Complex Number ● if-elif-else Statement First of all, the first
condition is evaluated, if it is true then
Boolean Float respective statements are processed.
Otherwise, the next condition is evaluated to
Sets process another statements. This process is
Python continued for several times.
Data None
Types
● nested if Statement Nested means if
String
statements or if-else statements are placed in
Sequence the statement block of if statement or else
Type List
statement.
Tuple 15. Iterative Statements Iteration is the repetition of a
Mapping
process in order to generate an outcome. Iterative
Dictionary statements or loops enable a program with a cyclic
flow of logic.
● while Loop This loop tests for its ending
11. Mutable and Immutable Types Every variable in
condition before executing the statements
Python holds an instance of an object. There are
enclosed in the loop body even the first time.
two types of objects in Python as follows
● for Loop This loop encloses one or more
(i) Mutable Types The values of mutable types can statements that form the body of the loop, the
be changed after it is created. These are list, statements in the loop repeat continuously a
dictionary and sets. certain number of times.
(ii) Immutable Types The values of immutable This loop is also known as entry control loop, as
cannot be changed after it is created.These are condition is checked before entering into the
integer, float, boolean, string and tuple. scope of the loop.
12. Control Structure A control structure is a 16. Jump Statements These statements allow altering
programming language construct which affects the the flow of a program by performing jumps to
flow of the execution of program. specific locations. The jump statement defined in
13. Sequence Statements Sequence statements refer Python are
to the instructions that are executed in the ● break Statement This statement alters the
sequence in which they are written in the program. normal flow of execution as it terminates the
14. Selection Statements Selection statement is a current loop and resumes execution of the
control statement that allows statement choosing statement following that loop.
● continue Statement When a continue statement
two or more execution paths in a program.
is encountered, the control skips the execution of
These statements allow a program to execute a remaining statements inside the body of the loop
statement or a set of statements depending upon a for the current iteration and jumps to the
given condition. beginning of the loop for the next iteration.
ONE DAY REVISION
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 03
https://t.me/cbseexamsweb
04 CBSE Sample Paper Computer Science Class XII (Term I)
Some common form of program errors are as (b) Run-time Errors In a program, a run-time
given below error is an error that occurs while program is
(a) Compile-time Errors All the errors that are running after being successfully compiled. It
detected and displayed by the compiler or is caused by some illegal operations taking
interpreter are known as compile-time errors. place or inavailability of desired or required
conditions for the execution of program.
There are two categories of compile-time
errors as follows (c) Logical Errors Logical errors occur when
● Syntax Error When a formal set of rules
the program does not give any error but still
defined for writing a program in a gives an incorrect output. These errors occur
particular language, is not followed then due to mistakes of the programmer.
error raised is known as syntax error. (ii) Python Exception An exception can be defined
● Semantic Error A programming error that as an abnormal condition in a program resulting
arises from a misunderstanding of the in the disruption to the flow of the program.
meaning or effect of some construct in a (iii) Exception Handling Exception handling is a
programming language is known as construct in some programming languages to
semantic error. handle or deal with errors automatically.
● Functions
1. A function can be defined as the organised block Function can be called multiple times with different
of reusable code, which can be called whenever expressions as the actual parameters.
required. It is basically named unit of a group of 5. Parameters and Arguments A parameter is a
proper statements. variable used to define a particular value during a
2. Types of Python Function There are three types function definition.
of functions in Python, which are given below An argument is a value passed to the function during
(i) Built-in Function Built-in functions are known the function call which is received for corresponding
as library functions. These are pre-defined parameter defined in function header.
functions in Python programming system that 6. Passing Parameters
are always available for use. ● Default Parameter Values It instructs the compiler
e.g. type(), input(), print() etc. what value to pass for a parameter if the
(ii) User Defined Functions Python provides programmer deliberately misses the matching
facility for programmers to define their own argument of that parameter in the function call
functions according to their requirements. Those statement.
functions defined by programmers are known as ● Keyword (Named) Arguments Using keyword
user defined functions. argument, you can declare value using name.
e.g. Function for finding factorial, function for Python provides a way of writing function calls
checking whether a number is prime or not, etc. where you can write any argument in any order,
but value should be in right form.
(iii) Function Defined in Modules In Python, there
● Positional Arguments Positional arguments are
are some functions that are pre-defined in
arguments that need to be included in the proper
specific modules.
position or order.
e.g. sin(), cos() are contained in math module,
mean(), mode() are in statistics module etc. The first position argument always needs to be
listed first when the function is called. The second
3. Defining a Function Function contain ‘def ’
positional argument needs to be listed second and
keyword to provide the required functionality. The
ONE DAY REVISION
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 05
● Functions not Returning Any Value (Void Any other function of the program cannot use them
Functions) When a function does not return a without receiving as the argument.
value, we can say it is a void function. Void
functions are also known as non-fruitful (ii) Global Variable (Global Scope) A variable
functions. Methods in Python do not return any declared outside of all functions in a program has
value. global scope and is known as global variable.
Global variable is usable for all functions of Python
8. Scope of Variables A variable defined inside a
program without declaration in their body or
function cannot be accessed outside it.
without receiving as the arguments.
Scope of variables in Python program, shows the
9. Namespace A namespace is basically a system to
area where you can use it. The variables are
make sure that all the names in a program are unique
treated differently in different functions.
and can be used without any conflict. Python
There are two kinds of scope of variable in implements namespaces as dictionaries.
Python, which are described below:
In Python, the LEGB (Local, Enclosed, Global,
(i) Local Variable (Local Scope) A variable that Built-in) rule is used to decide the order in which the
is defined inside any function or a block is namespaces are to be searched for scope resolution.
known as a local variable.
● File Handling
1. Data File Data files are the files that store and some point. Python provides mainly four types of
preserve data released to a particular application. read methods to read data from file.
Computers store every file as a collection of 0s ● read() This method returns a string containing all
and 1s, i.e. in binary form. Therefore, every file is characters in a file.
basically just a series of bytes stored. Syntax <FileHandle>.read()
2. Text File It is a sequence of characters consisting ● read([size]) This method specifies how many
of alphabets, numbers and other special symbols. characters the string should return.
It stores information in ASCII characters. In text Syntax <FileHandle>.read(n)
file, each line of text is terminated with a special ● readline() This method will read from a file line by
character known as EOL (End of Line) or delimiter. line. For readline(), a line is terminated by ‘\n’ or
End of Line (EOL) (i.e. new line character). When
The file extension of text file is .txt. end of file is reached, readline() will return an
(i) Opening a File In file handling, the first empty string.
requirement is opening a file. Once a file is Syntax <FileHandle>.readline()
opened, read, write, append, close, etc., can be ● readlines() This method will return a list of strings,
performed on the file. To open a file, open() each separated by ‘\n’.
method is used in Python.
This method reads all rows and retains the
(ii) Closing a File It is important to close files as newlines character that is at the end of every row.
soon as you have finished your work with file.
Opened file is closed by calling the close() Syntax <FileHandle>.readlines()
method of its file objects. (v) flush() Method This method will force out any
(iii) Writing into Files For writing to a file, we first unsaved data that exists in a program buffer to the
need to open it in write or append mode. In actual file.
Python, there are two methods of file objects Python automatically flushes the files when
which are used to write data into a files. closing them. But you may want to flush the data
ONE DAY REVISION
https://t.me/cbseexamsweb
06 CBSE Sample Paper Computer Science Class XII (Term I)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 07
THE
QUALIFIERS
Chapterwise Set of MCQs to Check Preparation
Level of Each Chapter
https://t.me/cbseexamsweb
08 CBSE Sample Paper Computer Science Class XII (Term I)
if (value% mul==0):
print(value*mul)
else:
print(value+mul)
(a) 13 (b) 13
14 13
15 13
(c) 3 (d) Error
10
13
a=3
while (a<12) :
print(a, end= ‘ ’)
a = a + 2
(a) 3 4 5 6 7 8 9 10 11 12 (b) 3 4 5 6 7 8 9 10 11
(c) 3 5 7 9 11 (d) 5 7 9 11
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 09
print(2)
(a) 1 (b) 1 (c) 1 (d) 1
3 2 3 2
5 3 5 3
2 5
2
https://t.me/cbseexamsweb
10 CBSE Sample Paper Computer Science Class XII (Term I)
15. What will be the output of the following Python code snippet?
x = ‘ARIHANT’
for i in range(len(x)):
x[i].lower()
print(x)
(a) ARIHANT (b) arihant (c) Arihant (d) Error
Answers
1. (c) 2. (c) 3. (a) 4. (d) 5. (b) For Detailed Solutions
6. (a) 7. (a) 8. (b) 9. (c) 10. (c)
Scan the code
11. (a) 12. (c) 13. (a) 14. (c) 15. (a)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 11
8. Which of the following option will not result in an error when performed on tuple in
Python, where tup1=(5, 6, 8, 9)?
(a) tup1[1]=12 (b) tup1.append(2) (c) tup=tup1+tup1 (d) tup1.sort()
9. dic1={“A”:15,“B”:16,“C”:17}
print(dic1[1])
What will be the output of above Python code?
(a) B (b) 16 (c) {“B”:16} (d) Error
11. Which of the following two Python codes will give same output?
If tup1=(1, 2, 3, 4, 5)
(i) print(tup1[:-1]) (ii) print(tup1[0:5])
(iii) print(tup1[0:4]) (iv) print(tup1[-4:])
(a) i, ii (b) ii, iv
(c) ii, v (d) i, iii
https://t.me/cbseexamsweb
12 CBSE Sample Paper Computer Science Class XII (Term I)
for i in num:
sum += num[i]
print(len(num) + sum)
(a) 54 (b) 38
(c) 33 (d) 59
Answers
1. (d) 2. (a) 3. (b) 4. (b) 5. (b) For Detailed Solutions
6. (c) 7. (d) 8. (c) 9. (d) 10. (b) Scan the code
11. (d) 12. (a) 13. (d) 14. (d) 15. (a)
3. Functions
Direction (Q. Nos. 1-15) Each of the question has four options out of which only one is correct.
Select the correct option as your answer.
1. Which is/are the advantage(s) of functions in Python?
(a) Reducing duplication of code
(b) Decomposing complex problems into simpler pieces
(c) Improving clarity of the code
(d) All of the mentioned
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 13
7. Suppose there is a list such that: list1=[1,2,3]. If we want to print this list in reverse
order, which of the following methods should be used?
(a) reverse(list1) (b) list(reverse[(list1)])
(c) reversed(list1) (d) list(reversed(list1))
https://t.me/cbseexamsweb
14 CBSE Sample Paper Computer Science Class XII (Term I)
find()
(a) H2LL5 (b) H2L45 (c) 1E3L5 (d) Error
Answers
1. (d) 2. (a) 3. (c) 4. (c) 5. (a)
For Detailed Solutions
6. (b) 7. (d) 8. (a) 9. (b) 10. (a)
Scan the code
11. (d) 12. (b) 13. (b) 14. (b) 15. (c)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 15
4. File Handling
Direction (Q. Nos. 1-15) Each of the question has four options out of which only one is correct.
Select the correct option as your answer.
1. To read three characters from a file object f, we use ……… .
(a) f.read(3) (b) f.read() (c) f.readline() (d) f.readlines()
s=myfile.read(10)
print(s)
s1=myfile.read(15)
print(s1)
myfile.close()
(a) Education (b) Education
Hub Learning is Hub
Learning is
https://t.me/cbseexamsweb
16 CBSE Sample Paper Computer Science Class XII (Term I)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 17
f.close( )
(a) Delete the 3rd word from file (b) Delete the 4th word from file
(c) Delete the 3rd word from file at end (d) Error
https://t.me/cbseexamsweb
18 CBSE Sample Paper Computer Science Class XII (Term I)
CBSE
QUESTION BANK
Case Study Based Questions
1. Rohit, a student of Class 12th, 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(“Class : ”)
section = input(“Enter Section : ”)
rec = [_____] #Statement 4
data.append(rec)
stuwriter. _____ (data) #Statement 5
fh.close()
(i) Identify the suitable code for blank space in line marked as Statement 1.
(a) csv file (b) CSV
CBSE QUESTION BANK
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 19
(v) Choose the function name that should be used in the blank space of line marked as Statement 5 to
create the desired CSV file?
(a) dump() (b) load() (c) writerows() (d) writerow()
2. Amritya Seth is a programmer, who has recently been given a task to write a Python code to
perform the following binary file operations with the help of two user defined
functions/modules:
(a) AddStudents() to create a binary file called STUDENT.DAT containing student information –
roll number, name and marks (out of 100) of each student.
(b) GetStudents() to display the name and percentage of those students who have a percentage
greater than 75. In case there is no student having percentage > 75, the function displays an
appropriate message. The function should also display the average percent.
He has succeeded in writing partial code and has missed out certain statements, so he has left
certain queries in comment lines. You as an expert of Python have to provide the missing
statements and other related queries based on the following code of Amritya.
import pickle
def AddStudents():
____________ #1 statement to open the binary file to write data
while True:
Rno = int(input(“Rno :”))
Name = input(“Name:”)
Percent = float(input(“Percent :”))
L = [Rno, Name, Percent]
____________ #2 statement to write the list L into the file
Choice = input(“enter more (y/n): ”)
if Choice in “nN”:
break
F.close()
def GetStudents():
Total=0
Countrec=0
Countabove75=0
with open(“STUDENT.DAT”,“rb”) as F:
while True:
try:
____________ #3 statement to read from the file
Countrec+=1
Total+=R[2]
if R[2] > 75:
CBSE QUESTION BANK
https://t.me/cbseexamsweb
20 CBSE Sample Paper Computer Science Class XII (Term I)
Answer any four questions (out of five) from the below mentioned questions.
(i) Which of the following commands is used to open the file “STUDENT.DAT” for writing only in
binary format? (marked as #1 in the Python code)
(a) F= open(“STUDENT.DAT”,‘wb’) (b) F= open(“STUDENT.DAT”,‘w’)
(c) F= open(“STUDENT.DAT”,‘wb+’) (d) F= open(“STUDENT.DAT”,‘w+’)
(ii) Which of the following commands is used to write the list L into the binary file
‘STUDENT.DAT’? (marked as #2 in the Python code)
(a) pickle.write(L,f) (b) pickle.write(f, L)
(c) pickle.dump(L,F) (d) f=pickle.dump(L)
(iii) Which of the following commands is used to read each record from the binary file
‘STUDENT.DAT’? (marked as #3 in the Python code)
(a) R = pickle.load(F) (b) pickle.read(r,f) (c) r= pickle.read(f) (d) pickle.load(r,f)
(iv) Which of the following statement(s) are correct regarding the file access modes?
(a) ‘r+’ opens a file for both reading and writing. File object points to its beginning.
(b) ‘w+’ opens a file for both writing and reading. Adds at the end of the existing file, if it exists and
creates a new one, if it does not exist.
(c) ‘wb’ opens a file for reading and writing in binary format. Overwrites the file, if it exists and
creates a new one, if it does not exist.
(d) ‘a’ opens a file for appending. The file pointer is at the start of the file, if the file exists.
(v) Which of the following statements correctly explain the function of seek() method?
(a) Tells the current position within the file.
(b) Determines if you can move the file position or not.
(c) Indicates that the next read or write occurs from that position in a file.
(d) Moves the current file position to a given specified position
3. Krrishnav is looking for his dream job but has some restrictions. He loves Delhi and would take a
job there, if he is paid over ` 40000 a month. He hates Chennai and demands at least ` 100000 to
work there. In any another location, he is willing to work for ` 60000 a month. The following code
shows his basic strategy for evaluating a job offer.
pay= _________
location= _________
if location == “Mumbai”:
print (“I’ll take it!”) #Statement 1
elif location == “Chennai”:
if pay < 100000:
print (“No way”) #Statement 2
else:
print(“I am willing!”) #Statement 3
elif location == “Delhi” and pay > 40000:
print(“I am happy to join”) #Statement 4
elif pay > 60000:
CBSE QUESTION BANK
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 21
4. Consider the following code and answer the questions that follow:
Book={1:‘Thriller’, 2:‘Mystery’, 3:‘Crime’, 4:‘Children Stories’}
Library ={‘5’:‘Madras Diaries’,‘6’:‘Malgudi Days’}
(i) Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime Thriller’. He has
written the following command:
Book[‘Crime’]=’Crime Thriller’
But he is not getting the answer. Help him choose the correct command:
(a) Book[2]=‘Crime Thriller’ (b) Book[3]=‘Crime Thriller’
(c) Book[2]=(‘Crime Thriller’) (d) Book[3] =(‘Crime Thriller’)
(ii) The command to merge the dictionary Book with Library the command would be:
(a) d=Book+Library (b) print(Book+Library)
(c) Book.update(Library) (d) Library.update(Book)
(iii) What will be the output of the following line of code:
print(list(Library))
(a) [‘5’,‘Madras Diaries’,‘6’,‘Malgudi Days’] (b) (‘5’,’Madras Diaries’,‘6’,‘Malgudi Days’)
(c) [‘Madras Diaries’,‘Malgudi Days’] (d) [‘5’,‘6’]
(iv) In order to check whether the key 2 is present in the dictionary Book, Ramesh uses the following
command:
2 in Book
He gets the answer ‘True’. Now to check whether the name ‘Madras Diaries’ exists in the
dictionary Library, he uses the following command:
‘Madras Diaries’ in Library
But he gets the answer as ‘False’. Select the correct reason for this.
(a) We cannot use the in function with values. It can be used with keys only.
(b) We must use the function Library.values() along with the in operator.
(c) We can use the Library.items() function instead of the in operator.
(d) Both (b) and (c)
(v) With reference to the above declared dictionaries, predict the output of the following code
fragments.
CBSE QUESTION BANK
Code 1 Code 2
Library=Book Library=Book.copy()
Library.pop(2) Library.pop(2)
print(Library) print(Library)
print(Book) print(Book)
https://t.me/cbseexamsweb
22 CBSE Sample Paper Computer Science Class XII (Term I)
5. Arun, during Practical Examination of Computer Science, has been assigned an incomplete
search() function to search in a pickled file student.dat. The file student.dat is created by his
teacher and the following information is known about the file.
l
File contains details of students in [roll_no,name,marks] format.
l
File contains details of 10 students (i.e. from roll_no 1 to 10) and separate list of each student is
written in the binary file using dump().
Arun has been assigned the task to complete the code and print details of roll number 1.
def search():
f = open(“student.dat”,____) #Statement 1
____: #Statement 2
while True:
rec = pickle.____ #Statement 3
if(____): #Statement 4
print(rec)
except:
pass
____ #Statement 5
(i) In which mode, Arun should open the file in Statement 1?
(a) r (b) r+ (c) rb (d) wb
(ii) Identify the suitable code to be used at blank space in line marked as Statement 2.
(a) if(rec[0]==1) (b) for i in range(10) (c) try (d) pass
(iii) Identify the function (with argument), to be used at blank space in line marked as Statement 3.
CBSE QUESTION BANK
6. Radha Shah is a programmer, who has recently been given a task to write a Python code to
perform the following CSV file operations with the help of two user defined functions/modules:
(a) CSVOpen() : to create a CSV file called BOOKS.CSV in append mode containing information of
books – Title, Author and Price.
(b) CSVRead() : to display the records from the CSV file called BOOKS.CSV where the field title
starts with ‘R’.
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 23
She has succeeded in writing partial code and has missed out certain statements, so she has left
certain queries in comment lines.
import csv
def CSVOpen():
with open(‘books.csv’,‘______’,newline=‘ ’) as csvf: #Statement 1
cw=______ #Statement 2
______ #Statement 3
cw.writerow([‘Rapunzel’,‘Jack’,300])
cw.writerow([‘Barbie’,‘Doll’,900])
cw.writerow([‘Johnny’,‘Jane’,280])
def CSVRead():
try:
with open(‘books.csv’,‘r’) as csvf:
cr=______ #Statement 4
for r in cr:
if ______: #Statement 5
print(r)
except:
print(‘File Not Found’)
CSVOpen()
CSVRead()
You as an expert of Python have to provide the missing statements and other related queries
based on the following code of Radha.
Answer any four questions (out of five) from the below mentioned questions.
(i) Choose the appropriate mode in which the file is to be opened in append mode (Statement 1).
(a) w+ (b) ab (c) r+ (d) a
(ii) Which statement will be used to create a csv writer object in Statement 2?
(a) csv.write(csvf) (b) csv.writer(csvf)
(c) csvf.writer() (d) cs.writer(csvf)
(iii) Choose the correct option for Statement 3 to write the names of the column headings in the CSV
file, BOOKS.CSV.
(a) cw.writerow(‘Title’,‘Author’,‘Price’) (b) cw.writerow([‘Title’,‘Author’,‘Price’])
(c) cw.writerows(‘Title’,‘Author’,‘Price’) (d) cw.writerows([‘Title’,‘Author’,‘Price’])
(iv) Which statement will be used to read a csv file in Statement 4?
(a) cs.read(csvf) (b) csv.reader(csvf)
(c) csvf.read() (d) csvf.reader(cs)
(v) Fill in the appropriate statement to check the field Title starting with ‘R’ for Statement 5 in the
above program.
(a) r[0][0]==‘R’ (b) r[1][0]==‘R’ (c) r[0][1]==‘R’ (d) r[1][1]==‘R’
CBSE QUESTION BANK
7. Priyank is a software developer with a reputed firm. He has been given the task to computerise
the operations for which he is developing a form which will accept customer data as follows:
The DATA TO BE ENTERED IS :
Name
Age
Items bought (all the items that the customer bought)
Bill amount
(i) Choose the most appropriate data type to store the above information in the given sequence.
(a) string, tuple, float, integer (b) string, integer, dictionary, float
(c) string, integer, integer, float (d) string, integer, list, float
https://t.me/cbseexamsweb
24 CBSE Sample Paper Computer Science Class XII (Term I)
(ii) Now the data of each customer needs to be organised such that the customer can be identified by
name followed by the age, item list and bill amount. Choose the appropriate data type that will
help Priyank accomplish this task.
(a) List (b) Dictionary
(c) Nested Dictionary (d) Tuple
(iii) Which of the following is the correct way of storing information of customers named ‘Paritosh’
and ‘Bhavesh’ with respect to the option chosen above?
(a) customers= {‘Paritosh’:24,[‘Printed Paper’, ‘ Penstand’], 3409, ‘Bhavesh’: 45,[‘A4 Rim’,’Printer
Cartridge’, ‘Pen Carton’, ‘Gift Wrap’], 8099.99 }
(b) customers={‘Paritosh’:[24,[‘Printed Paper’, ‘ Penstand’], 3409], ‘Bhavesh’: [45,[‘A4 Rim’,’Printer
Cartridge’, ‘Pen Carton’, ‘Gift Wrap’], 8099.99] }
(c) customers= [‘Paritosh’:24,‘Printed Paper’, ‘ Penstand’, 3409, ‘Bhavesh’: 45,‘A4 Rim’,’Printer
Cartridge’, ‘Pen Carton’, ‘Gift Wrap’, 8099.99 ]
(d) customers=(‘Paritosh’:24,[‘Printed Paper’, ‘ Penstand’], 3409, ‘Bhavesh’: 45,[‘A4 Rim’,’Printer
Cartridge’, ‘Pen Carton’, ‘Gift Wrap’], 8099.99 )
(iv) In order to calculate the total bill amount for 15 customers, Priyank
Statement 1 must use a variable of the type float to store the sum.
Statement 2 may use a loop to iterate over the values.
(a) Both statements are correct.
(b) Statement 1 is correct, but statement 2 is not.
(c) Both statements are incorrect.
(d) Statement 1 is incorrect but statement 2 is correct.
8. Your teacher has given you a method/function FilterWords() in Python which read lines from a
text file NewsLetter.TXT and display those words, which are lesser than 4 characters. Your
teachers intentionally kept few blanks in between the code and asked you to fill the blanks, so
that the code will run to find desired result. Do the needful with the following Python code.
def FilterWords():
c=0
file=open(‘NewsLetter.TXT’, ‘_____’) #Statement 1
line = file._____ #Statement 2
word = _____ #Statement 3
for c in word:
if _____: #Statement 4
print(c)
______ #Statement 5
FilterWords()
(i) Write mode of opening the file in Statement 1?
(a) a (b) ab
(c) w (d) r
CBSE QUESTION BANK
(ii) Fill in the blank in Statement 2 to read the data from the file.
(a) File.Read() (b) file.read()
(c) read.lines( ) (d) readlines( )
(iii) Fill in the blank in Statement 3 to read data word by word.
(a) Line.Split() (b) Line.split()
(c) line.split() (d) split.word()
(iv) Fill in the blank in Statement 4, which display the word having lesser than 4 characters.
(a) len(c) ==4 (b) len(c)<4
(c) len ( )= =3 (d) len ( )==4
(v) Fill in the blank in Statement 5 to close the file.
(a) file.close() (b) File.Close()
(c) Close() (d) end()
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 25
Answers
1. (i) c (ii) b (iii) c (iv) d (v) c 2. (i) a (ii) c (iii) a (iv) a (v) d 3. (i) b (ii) d (iii) d (iv) c (v) d
4. (i) b (ii) d (iii) d (iv) b (v) c 5. (i) c (ii) c (iii) c (iv) d (v) c 6. (i) d (ii) b (iii) b (iv) b (v) a
7. (i) d (ii) c (iii) b (iv) a 8. (i) d (ii) b (iii) c (iv) b (v) a
SOLUTIONS
1. (i) csv is the correct code to fill up the blank is (ii) When location = “Surat”, pay = 50000
Statement 1, which is to be imported. entered by user then statement 6 will be
(ii) This code opens a file student.csv in write execute.
mode because append() method is using. (iii) When location = “Any Other City”, pay =1
So, correct missing code is entered by user then statement 6 will be
“Student.csv”, “w” execute because it does not satisfied any
(iii) writer(fh) should be used in blank space in given condition.
Statement 3. csv. writer is used to insert (iv) When location = “Delhi”, pay = 50000
data to the CSV file. entered by user then statement 4 will be
(iv) Suitable code for blank space in Statement execute.
4 is roll_no, name, class, section. (v) When location = “Lucknow”, pay =65000
(v) writerows() should be used in blank space entered by user then statement 5 will be
in Statement 5. execute.
writerows() function writes each sequence 4. (i) To update the element of dictionary which
in a list as a comma separated line of items is already exist, following syntax is used
in the file. dictionary name [key] = value
2. (i) To open the file binary, open() function is In question, to change the value of key 3
used. Ramesh have to give key instead of value.
Correct answer is So, the correct code is
F=open(“STUDENT.DAT”, ‘wb’), if file Book [3] = ‘Crime Thriller’
name is “STUDENT.DAT”.
(ii) To merge two dictionaries, following
(ii) To write the list L into file, pickle.dump syntax is used
(L,F) is used. For using dump() method,
dictionary2. update (dictionary1)
you first have to import the pickle module.
So, correct code to merge dictionaries
(iii) The correct statement used in marked as #3
Book and Library are
is R=pickle.load(F) because load()
method is used to load data from a binary Library. update (Book)
file. (iii) list () is used to convert the sequence types
(iv) The correct statement regarding the file into lists.
access modes is r+ opens a file for the both (iv) in operator considers only keys of
dictionary. If we want to check the
CBSE QUESTION BANK
https://t.me/cbseexamsweb
26 CBSE Sample Paper Computer Science Class XII (Term I)
correct code is csv. reader (csvf). 4, which display the word having lesser than
(v) Title is the first column of CSV file, so its 4 characters.
index would be r [0] [0]. (v) file.close() is used to close the file. It is
Condition to check the field Title starting important to close the files as soon as you
with ‘R’ will be r [0] [0] = ‘R’. have finished your work with file.
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 27
Latest CBSE
SAMPLE PAPER
Latest Sample Question Paper for Class X (Term I)
Issued by CBSE on 2 Sept, 2021
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
2. Consider the declaration L = (1, ‘Python’, ‘3.14’). What will be the data type of L?
(a) list (b) tuple (c) dictionary (d) string
3. Given an object obj1= (10, 20, 30, 40, 50, 60, 70, 80, 90). What will be the output of
Latest CBSE SAMPLE PAPER
print(obj1[3:7:2])?
(a) (40,50,60,70,80) (b) (40,50,60,70) (c) (40,50,60) (d) (40,60)
5. Which of the following option can be used to read the first line of a text file
‘‘Myfile.txt’’?
(a) myfile = open(‘Myfile.txt’); print(myfile.read(line))
(b) myfile = open(‘Myfile.txt’,‘r’); print(myfile.read(1))
(c) myfile = open(‘Myfile.txt’); print(myfile.readline())
(d) myfile = open(‘Myfile.txt’); print(myfile.readlines())
https://t.me/cbseexamsweb
28 CBSE Sample Paper Computer Science Class XII (Term I)
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(n-3) (b) myfile.read(n)
(c) myfile.readline() (d) myfile.readlines()
7. A text file ‘student.txt’ is stored in the storage device. Identify the correct option out of
the following options to open the file in read mode.
(i) myfile = open(‘student.txt’,‘a’)
(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)
9. Which of the following operator cannot be used with string data type?
(a) + (b) in (c) * (d) /
10. Given an object obj1 = (10, 15, 25, 30). Identify the statement that will result in an error.
(a) print(obj1[2]) (b) obj1[2] = 20
(c) print(min(obj1)) (d) print(len(obj1))
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 end of line (EOL) character translation takes place.
(c) Every line ends with a new line character.
(d) Pickle module is used for reading and writing.
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 29
18. Which of the following characters act as default delimiter in a CSV file?
(a) Colon (:) (b) Hyphen) (-)
(c) Comma (,) (d) Vertical line (|)
19. Given below is one way of opening a file ‘‘Student.csv’’ in write mode.
myfile = open(“Student.csv”,“w”,newline=‘ ’).
What is the importance of newline=‘ ’?
(a) A new line gets added to the file.
(b) Empty string gets appended to the first line.
(c) Empty string gets appended to all lines.
(d) EOL character translation is suppressed.
21. Which of the following is not a function/method of the csv module in Python?
(a) read() (b) reader()
(c) writer() (d) writerow()
22. Which one of the following is the default extension of a Python file?
(a) .exe (b) .p++
Latest CBSE SAMPLE PAPER
24. Which of the following statement opens a binary file ‘record.bin’ in write mode and
writes an object 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)
https://t.me/cbseexamsweb
30 CBSE Sample Paper Computer Science Class XII (Term I)
Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 31
32. Raghav is trying to write an object obj1 = (1,2,3,4,5) on a binary file “test.bin”. Consider
the following code written by him.
import pickle
obj1 = (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,obj1) (b) dump(obj1, myfile)
(c) write(obj1,myfile) (d) load(myfile,obj1)
33. The content of a binary file “employee.dat” is shown below, where the Header is not a
part of file content (i.e. only Row1 to Row5 are present in the file).
Header Empno Empname Salar
Row1 101 Anuj 50000
Row2 102 Arijita 40000
Row3 103 Hanika 30000
Row4 104 Firoz 60000
Row5 105 Vijaylakshami 40000
def display(eno):
f=open(“employee.dat”,“rb”)
totSum=0
try:
while True:
R=pickle.load(f)
if R[0]==eno:
________ #Line1
Latest CBSE SAMPLE PAPER
totSum=totSum+R[2]
except:
f.close()
print(totSum)
When the above mentioned function, display (103) is executed, the output displayed is
190000. Which of the following statement should be used in the blank space of the line
marked as Line1 to obtain the above output?
(a) jump (b) break (c) continue (d) return
https://t.me/cbseexamsweb
32 CBSE Sample Paper Computer Science Class XII (Term I)
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
38. Which of the following option can be the output for 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
Latest CBSE SAMPLE PAPER
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 33
myfile.close()
(a) 5 (b) 25 (c) 26 (d) 27
https://t.me/cbseexamsweb
34 CBSE Sample Paper Computer Science Class XII (Term I)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 35
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
Section C
Latest CBSE SAMPLE PAPER
https://t.me/cbseexamsweb
36 CBSE Sample Paper Computer Science Class XII (Term I)
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) csv module
51. Identify the missing code for blank space in the line marked as Statement 2.
(a) “Student.csv”,“wb” (b) “Student.csv”,“w”
(c) “Student.csv”,“r” (d) “Student.csv”,“rb”
52. Choose the function name (with argument) that should be used in the line marked as
Statement 3.
(a) reader(fh) (b) reader(MyFile)
(c) writer(fh) (d) writer(MyFile)
53. Identify the suitable code for the blank space in 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
Latest CBSE SAMPLE PAPER
55. Choose the function name that should be used in the blank space of the line marked as
Statement 6 to create the desired CSV file?
(a) dump() (b) load()
(c) writerows() (d) writerow()
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 37
Answers
1. (d) 2. (b) 3. (d) 4. (b) 5. (c) 6. (d) 7. (c) 8. (a) 9. (d) 10. (b)
11. (c) 12. (b) 13. (b) 14. (a) 15. (d) 16. (d) 17. (a) 18. (c) 19. (d) 20. (b)
21. (a) 22. (c) 23. (d) 24. (a) 25. (b) 26. (c) 27. (b) 28. (d) 29. (c) 30. (c)
31. (b) 32. (b) 33. (c) 34. (d) 35. (c) 36. (d) 37. (b) 38. (b) 39. (b) 40. (c)
41. (b) 42. (d) 43. (d) 44. (d) 45. (b) 46. (a) 47. (b) 48. (b) 49. (b) 50. (c)
51. (b) 52. (c) 53. (d) 54. (c) 55. (c)
SOLUTIONS
1. pass is invalid identifier because it is a 11. Binary file is a file that contains information in
keyword and keyword cannot use as identifier. the same format as it is held in memory. In
2. A tuple is an ordered sequence of elements of binary files, no delimiters or new line character
different data types such as integers, float, are used for a line and no translations occur
string, list or even a tuple. Elements of tuples here.
are put in parenthesis ( ) separated by commas. 12. tell() method tells you the current position
e.g. L = (1, ‘Python’, ‘3.14’) within the file, measured in bytes from the
beginning of the file.
3. obj1[3 : 7 : 2]
13. Pickling is used for object serialization.
It starts from index number 3 to index number Serialization is the process of transforming
7 with gap of 2 elements. data or an object in memory to a stream of
In obj1=(10, 20, 30, 40, 50, 60, 70, 80, 90). bytes.
element of index number 3 is 40 and after two 14. In myfile. seek (offset, reference_point),
elements of gap, element is 60. 0 is the default value of reference_point that
So, output is (40, 60). means use the beginning of the file as the
reference position.
4. If we try to read a text file that does not exist,
then it will give an error or exception. 15. Parts of a function header in Python are def
keyword, function name and parameter list.
5. readline() method will read from a file Syntax def function_name (parameters):
line-by-line. open() method is used to open the
file. To read the first line of a text file ‘‘Myfile. 16. Any parameter cannot have a default value
txt’’, code is unless all passing arguments appearing on its
right have their default value.
myfile=open (‘Myfile.txt’); print
(myfile.readline()) So, correct function header is
Latest CBSE SAMPLE PAPER
6. readlines() will return a list of strings, each def cal_si(p, r=8, t=2):
separated by ‘\n’. It helps to read the line from 17. To call a function, write function_name which
mid, or specific position. function you want to use.
7. ‘r’ (read) mode is default mode for text file. So, e.g. my_func()
myfile=open(‘student.txt’, ‘r’) and
18. CSV file stores tabular data in plain text. Each
myfile=open(‘student.txt’) are same.
line of the file is a data record. Each record
8. input() method reads a line from the input consists of one or more fields separated by
converts the line into a string by removing the commas.
trailing newline and returns it.
19. The importance of newline is EOL (End of
9. Strings are group of characters. It uses Line) translation is suppressed.
different operators as +, in, *, is, etc.
20. CSV stands for Comma Separated Values. It
But it does not use / operator. stores tabular data in plain text. Each line of
10. obj1[2]=20 means updation is not possible in the file is a data record.
tuple because tuple is immutable which cannot reader() in CSV represents the data in list
be change after creation. So, data type of rec will be list.
https://t.me/cbseexamsweb
38 CBSE Sample Paper Computer Science Class XII (Term I)
21. read() is not used with CSV file in Python. So, new list after both insert() statement is
While reader(), writer(), writerow(), lst1=[10, 15, 3, 20, 4, 25, 30]
writerows() are CSV methods. print(lst[-5]) will print the 5th element from
22. .py is the default extension of a Python file. last, i.e. 3.
23. Comments are used to add a remark or a note 32. dump() is used to write objects to a file. Before
in the source code that are ignored by the use the dump() method, you first have to
interpreter or compiler and are not executed by import the pickle module.
the compiler. Syntax
A single line comment starts with # and pickle.dump(object_to_pickle, FileObject)
a multi-line comment starts with ‘‘‘ ’’’. e.g. dump(obj1, myfile)
24. The correct code for given condition is 33. Correct jump statement to obtain given output
with open(‘record.bin’,‘wb’) as myfile : is continue. When a continue statement is
encountered, the control skips the execution of
pickle.dump(lst1, myfile) remaining statements inside the body of the
25. In Python, to access the element (values) from loop for the current iteration and jumps to the
a dictionary, keys are used. beginning of the loop for the next iteration.
26. Tuple T contains a single element, so * is used 34. sum=add(20,30) is invalid code, so it will not
as multiplication operator. produce any output.
So, T * 2 = 100 * 2 = 200 We can use as add(20, 30).
27. This program opens a file ‘Myfile’ in read 35. 16 - ( 4 + 2 ) * 5 + 2 * *3 * 4
mode. readlines() returns a list of strings; each = 16 - 6 * 5 + 2 * *3 * 4
separated by ‘\n’. len() will count the number = 16 - 6 * 5 + 8 * 4
of line from file. = 16 - 30 + 8 * 4
= 16 - 30 + 32
28. x is a nested list which contains two separate = 16 + 2 = 18
lists.
36. When my_func(50) will be called, then
x[1][2] denotes third element of second list, i.e. var1=50 var2=200
15.0.
var1=var1+10 = 50 + 10 = 60
29. x is equal to 2 so number starts to print from 2 var2=var2 - 10 = 200 - 10 = 190
till 8 because while has a condition x < 9.
return 60 + 190 = 250
So, correct output is 2345678.
when my_func() will be called, then
30. for loop starts from 1 to 9 with increment the
value by 2 var1 = 100 var2 = 200
Iteration 1 b = 1 a = 1 var1 = 100 + 10 = 110
var2 = 200 - 10 = 190
b = b + a + 2 = 1+1 + 2 = 4
return 110 + 190 = 300
Latest CBSE SAMPLE PAPER
Iteration 2 b = 4 a = 3
37. Before called the function display (20) the
b = 4 + 3 + 2 = 9 value of ‘value’ is 50 because it is globally
Iteration 3 b = 9 a = 5 define. So prints 50
b = 9 + 5 + 2 = 16 When function display (20) called, then
Iteration 4 b = 16 a = 7 N=20, value=25
b = 16 + 7 + 2 = 25 because here value is locally defined
Iteration 5 b = 25 a = 9 if 20% 7==0 : False
b = 25 + 9 + 2 + 36 else :
value=value - N = 25 - 20 = 5
prints 36
prints 5
31. insert() is used to insert an element at specified
Correct output is
position in the list.
50#5
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 39
38. Minimum index number for random module when myfunc() calls, it takes x = 3 and then
is 1and maximum index number is 3. x= x+2 =3+2 = 5
Value which will be accessed from list as Second print statement outside function takes
Mumbai, Chennai, Kolkata and its sequence x = 5, which is modified value of x.
will be same as they written.
45. This program counts the number of vowels
39. ChangeVal ([25, 8, 75, 12], 4) present (lowercase and uppercase both) in the file.
Iteration 1 M=25 46. This program counts those lines which are started
if 25 % 5 ==0 True with ‘T’.
M[i] = 25//5=5 47. School is root directory. Academics, Examination
if 5%3==0 False and Sports are sub directory. Syllabus.jpg,
print 5# Result.png and Achievement. jpg are files.
Iteration 2 M=8
Syntax for absolute path is
if 8%5==0 False
if 8%3==0 False Root directory/Sub directory/files …… .
prints 8# For syllabus. jpg,
Iteration 3 M=75 School/Academics/Syllabus. jpg
if 75% 5 ==0 True
48. readlines () method will return a list of strings,
M[i] = 75//5=15
each separated by ‘\n’.
if 15% 3 ==0 True
M[i] =15//3=5 49. tup1 is nested tuple in which [1,2] consider as one
prints 5# element or sub tuple.
Iteration 4 M=12 tup 1[2] [1] =3.14 will update the value of sub
if 12%5==0 False tuple.
if 12%3==0 True So, correct output is
M[i] = 12//3=4 (1, 2, [1, 3.14], 3)
prints 4#
50. CSV is the correct code to fill up the blank in
So, output is 5#8#5#4#
statement 1, which is to be imported.
40. This program counts the number of words
51. This code opens a file student.csv in write mode
present in file Myfile.txt.
because append() method is using. So, correct
41. Correct output is missing code is “Student.csv”, “w”.
pYTHOnN#a 52. writer(fh) should be used in blank space in
This program converts all uppercase into statement 3.
lowercase and all lowercase into uppercase. csv. writer is used to insert data to the csv file.
If any digit is found then it will put previous
53. Suitable code for blank space in statement 4 is
element from its position. Other than
alphabet and digit, converts with #. roll_no, name, class, section
Latest CBSE SAMPLE PAPER
42. This program opens a file ‘Myfile’ in read 54. rec is a variable which stores the value for
mode and after read the characters of file, roll_no, name, class, section.
counts each character and print total In statement 5, data will be appended in file with
number of characters including space. the help of rec variable.
43. This program counts the number of ‘umpty 55. writerows() should be used in blank space in
(both in lowercase and uppercase)’ present statement 6.
in given file ‘Myfile.txt’. writerows() function writes each sequence in a
44. First print statement outside function takes list as a comma separated line of items in the file.
x = 3 which is globally defined.
https://t.me/cbseexamsweb
https://t.me/cbseexamsweb
https://t.me/cbseexamsweb
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 43
SAMPLE PAPER 1
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
https://t.me/cbseexamsweb
44 CBSE Sample Paper Computer Science Class XII (Term I)
8. You can repeat the elements of the tuple using which operator?
(a) * (b) + (c) ** (d) %
13. In which file, no delimiters are used for line and no translations occur?
(a) Text file (b) Binary file (c) CSV file (d) None of these
14. Which attribute is used to return access mode with that file was opened?
(a) mode.file (b) mode.file.name (c) file.mode (d) file.mode.type
18. Suppose list1 is [56, 89, 75, 65, 99], what is the output of list1 [− 2]?
(a) Error (b) 75 (c) 99 (d) 65
20. dl={“abc”:5,“def”:6,“ghi”:7}
SAMPLE PAPER 1
print(d1[0])
What will be the output of above Python code?
(a) abc (b) 5 (c) {“abc”:5} (d) Error
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 45
22. str1=“659.31”
print(“str1”)
What will be the output of above Python code?
(a) 1 (b) 6/4 (c) 1.5 (d) str1
Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
https://t.me/cbseexamsweb
46 CBSE Sample Paper Computer Science Class XII (Term I)
32. Observe the following code and answer the question that follow.
File = open(“Mydata”, “a”)
_______#Blank
File. close()
Fill in the blank with statement to write “ABC” in the file “Mydata”.
(a) File.write() (b) File.write(ABC) (c) write(ABC) (d) File.write(“ABC”)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 47
35. Evaluate the following expression, when a = 10, b = 5 and identify the correct answer.
x = a*3//4+b//4+4−a+5//6
(a) 12 (b) 4 (c) 2 (d) 6
37. What possible output(s) are expected to be displayed on screen at the time of execution
of the program from the following code?
import random
ar = [2, 3, 4, 5, 6, 7]
minn = random.randint (1, 3)
maxn = random.randint (2, 4)
for i in range (minn, maxn + 1):
print (ar [i], end = ‘#’)
(a) 3# 4# 5# (b) 5# 6# 7# (c) 1# 4# 7# (d) 4# 5# 7#
for i in a:
print(i)
test((3,4,5,3,7))
(a) 3 (b) 3, 4, 5, 3, 7 (c) 3 4 5 3 7 (d) None of these
4
5
3
7
https://t.me/cbseexamsweb
48 CBSE Sample Paper Computer Science Class XII (Term I)
file.close()
(a) 2 (b) 3 (c) 4 (d) 5
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 49
print (x)
print (x)
(a) 5 (b) 5 (c) 6 (d) 6
3 4 4 3
46. Observe the code given below and find the output, if the content of file ‘‘student.txt’’ is
S01, Rahul Verma, First division
S02, Reetesh Deshmukh, First division
S03, Aaditya Mishra, Second division
S04, Aradhaya Sinha, Third division
S05, Manish Sharma,Third division
Hello
Mode. png
https://t.me/cbseexamsweb
50 CBSE Sample Paper Computer Science Class XII (Term I)
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
Shreya write a program to check if elements of a list are same or not, it read from front or
back.
a = [1, 2, 3, 3, 2, 1]
i = ______ #line 1
mid = (len (a))/2
same = True
while ______ #line 2
if a[i] ! = ______ : #line 3
print (“No”)
same = False
______ #line 4
______ #line 5
if same = = ______ : #line 6
print (“Yes”)
52. Choose the correct option to fill up the blank in line 3 as marked.
(a) a[len(a)] (b) a[len(a) − i] (c) a[len(a) − 1] (d) a[len(a)− i − 1]
53. Choose the correct option to fill up the blank in line 4 as marked.
(a) continue (b) label (c) goto (d) break
54. Choose the correct option to fill up the blank in line 5 as marked.
(a) i = i + 1 (b) i = i − 1 (c) i = i * i (d) i = i + mid
55. What value will be equal to ‘‘same’’ in if condition in line 6 as marked?
(a) False (b) True (c) 0 (d) 1
https://t.me/cbseexamsweb
OMR SHEET SP 1
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
52 CBSE Sample Paper Computer Science Class XII (Term I)
Answers
1. (d) 2. (c) 3. (a) 4. (c) 5. (c) 6. (b) 7. (d) 8. (a) 9. (a) 10. (c)
11. (b) 12. (a) 13. (b) 14. (c) 15. (b) 16. (c) 17. (c) 18. (d) 19. (b) 20. (d)
21. (b) 22. (d) 23. (b) 24. (b) 25. (b) 26. (b) 27. (a) 28. (c) 29. (b) 30. (c)
31. (c) 32. (d) 33. (d) 34. (b) 35. (c) 36. (a) 37. (a) 38. (c) 39. (a) 40. (b)
41. (a) 42. (c) 43. (a) 44. (d) 45. (b) 46. (d) 47. (b) 48. (a) 49. (c) 50. (b)
51. (c) 52. (d) 53. (d) 54. (a) 55. (b)
SOLUTIONS
1. Identation is a logical instructions, which Python 17. Elements of lists are stored in contagious
interpreter can read and execute. memory location is true regarding lists in
Python.
2. Comments are used to add a remark or a note in
the source code that are ignored by interpreter. 18. − 1 corresponds to the last index in the list,
Single line comments are shown by # symbol. − 2 represents the second last element and
so on.
3. Data type is a term that is used to show the kind
So, the output for list1 [− 2] is 65 because 65
of data values or the type of data that is expected
is second last element of list1.
to be handled. Numbers data type contains only
numeric value in Python. 19. In Python, a dictionary can have two same
values with different keys.
4. The index should be an integer. Index of 0 refers to
first element, 1 refers to second element and so on. 20. The given code will show an error. Because
0 is not a key in given dictionary abc, def
5. count() function is used to calculate total
and ghi considered as keys to the given
occurrence of given elements of list.
dictionary.
6. Tuple is a collection of Python objects separated
21. The values of a dictionary can be accessed
by commas as (,).
using keys but the keys of a dictionary
e.g. (3, 5, 9, 10) cannot be accessed using values.
7. Traversing a tuple is a technique to access an 22. Since in print statement, str1 is written
individual element of that tuple. inside double quotes, so it will simply print
8. * is a replication operator that can repeat the str1 directly.
elements of the tuple. 23. Strings are immutable which cannot be
9. Arguments are used to pass the value of a changed after creation. So, updation is not
variable to a function. possible. Hence, new values cannot be
10. non-void functions are also known as fruitful assigned at any index position in a string.
functions. These functions are used to create a 24. capitalize() function in string gives the
specific task. output by converting only the first character
11. A variable declared in a block is local to that of the string into uppercase and rest
characters into lowercase. However, upper()
block and is known as local variable.
function is used to return the whole string
12. LEGB stands for Local Enclosed Global Built-in. into uppercase.
SAMPLE PAPER 1
13. In binary file, no delimiters are used for line and 25. len() returns the length of the given string
no translations occur. str1, including spaces and considering ‘‘ ’’ as
14. file.mode attribute is used to return access mode a single character.
with that file was opened. 26. * is a replication operator that repeats the
15. write() method takes a string and writes it in the elements of the list.
file. If elements of list L are 34, 89, then the
output of L*3 will be three times of that list.
16. For readline(), a line is terminated by \n (new
line) or EOF (End Of File). i.e. 34, 89, 34, 89, 34, 89.
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 53
https://t.me/cbseexamsweb
54 CBSE Sample Paper Computer Science Class XII (Term I)
45. myfile variable opens the file ‘arihant.txt’ in 49. for statement can iterate over the elements of a
read mode and read the data of file sequence or string. It is used when you want to
word-for-word and store the data upto 15 traverse all characters of string.
bytes to variable s. Then finally print the 50. The initial value of i will be 0.
value of s. It also includes the spaces.
51. The correct condition is i < mid: , which will check
46. This program opens a file ‘student.txt’ in the value of i less than the value of ‘mid’ variable.
read mode. It reads the file line-by-line with
readlines() method and counts the number 52. The correct option to fill up the blank in line 3 is
of lines. a [len(a)−i −1].
47. The root directory is the first or top-most 53. The correct option to fill up the blank in line 4 is
directory in a hierarchy. In given figure, break, which will terminate the execution of if
ABC is the root directory, Hello is condition.
sub-directory and Mode.png is a file. 54. The correct code to fill up the blank in line 5 is
48. readlines() method will return a list of i = i + 1, which will increment the value of i by 1.
strings, each separated by ‘\n’. So, the data 55. if condition will be if (same = = True) :
type of s is list. When it becomes true, then it will print Yes.
SAMPLE PAPER 1
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 55
SAMPLE PAPER 2
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
4. Which of the following operators in Python are used to determine whether a value is of
a certain class or type?
(a) Identity operators (b) Membership operators
SAMPLE PAPER 2
https://t.me/cbseexamsweb
56 CBSE Sample Paper Computer Science Class XII (Term I)
9. The process of converting a data type into another data type is known as ............ .
(a) expression (b) operator
(c) type conversion (d) comparison
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 57
21. Which of the following operators has its associativity from right to left?
(a) + (b) //
(c) % (d) **
23. What will be the output of the following Python code snippet?
d1 = {“Neha”:86, “Yash”:92}
d2 = {“Neha”:86, “Yash”:88}
d1 > d2
(a) True (b) False (c) Error (d) None
Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
https://t.me/cbseexamsweb
58 CBSE Sample Paper Computer Science Class XII (Term I)
29. What will be the output of the following Python code snippet?
x = ‘abcd’
for i in range(len(x)):
print(x)
x = ‘a’
(a) a (b) abcd abcd abcd abcd
(c) a a a a (d) None of the mentioned
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 59
32. Sohan is a student of Class 12th. He got an assignment on Python language, in which
one question is
Write a tuple test = (3, 4, 8, 11, 2) on a binary file hello.bin. Consider the following code
written by him.
import pickle
test=(3, 4, 8, 11, 2)
file=open(“hello.bin”, “wb”)
pickle. —————————— # line 1
file.close()
Identify the missing code in line 1.
(a) dump (file, test) (b) dump (test, file)
(c) write (test, file) (d) load (file, test)
35. Evaluate the following expression and identify the correct answer.
SAMPLE PAPER 2
https://t.me/cbseexamsweb
60 CBSE Sample Paper Computer Science Class XII (Term I)
print power(5)
print power(5, 5)
(a) 625 (b) 625 (c) 3125 (d) Error
3125 625 3125
41. Find the output of the following code from given options.
def calcresult ():
i=9
while i > 1 :
if (i % 2 = = 0):
x = i% 2
i = i− 1
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 61
else:
i = i − 2
x = i
print (x * * 2)
(a) 81 (b) 81 (c) 81 (d) 49
49 49 49 25
25 25 25 9
9 9 1
1
44. A text file “Quotes.txt” has the following data written in it.
Living a life you can be proud of
Doing your best
Spending your time with people
for i in z:
count=count+1
print (count)
(a) 14 (b) 15 (c) 16 (d) 29
45. What will be the output of the following Python code snippet?
a={}
a[1] = 1
a[‘1’] = 2
a[1]=a[1]+1
https://t.me/cbseexamsweb
62 CBSE Sample Paper Computer Science Class XII (Term I)
count = 0
for i in a:
count+= a[i]
print(count)
(a) 1
(b) 2
(c) 4
(d) Error, the keys cannot be a mixture of letters and numbers
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 63
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
51. Choose the correct option to fill up the blank in line 2 as marked.
(a) i (b) count (c) i + 1 (d) count +1
52. Choose the correct option to fill up the blank in line 3 as marked.
(a) lower (b) upper (c) islower (d) isupper
53. Choose the correct option to fill up the blank in line 4 as marked.
(a) 1 (b) i * 2 (c) i/2 (d) i
54. Choose the correct option to fill up the blank in line 5 as marked.
SAMPLE PAPER 2
55. Choose the correct option to fill up the blank in line 6 as marked.
(a) newstr (b) str (c) makenew (d) mystr
https://t.me/cbseexamsweb
OMR SHEET SP 2
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 65
Answers
1. (a) 2. (d) 3. (a) 4. (a) 5. (b) 6. (a) 7. (c) 8. (a) 9. (c) 10. (b)
11. (b) 12. (c) 13. (b) 14. (a) 15. (c) 16. (d) 17. (b) 18. (b) 19. (c) 20. (b)
21. (d) 22. (a) 23. (c) 24. (b) 25. (d) 26. (b) 27. (c) 28. (a) 29. (d) 30. (d)
31. (d) 32. (b) 33. (c) 34. (a) 35. (b) 36. (a) 37. (c) 38. (b) 39. (d) 40. (d)
41. (d) 42. (a) 43. (c) 44. (c) 45. (c) 46. (c) 47. (d) 48. (a) 49. (b) 50. (a)
51. (b) 52. (c) 53. (d) 54. (a) 55. (c)
SOLUTIONS
1. Pickling is a way to convey a Python object 15. Flowchart are drawn using certain special
into a character stream. purpose symbols.
2. x is an access mode to open the CSV file. It is 16. The print() function is a built-in function,
used to create a new file in csv. which prints a value directly to the system
3. Relative path does not start with a leading output.
forward slash and is interpreted from the 17. round() is a built-in function, which rounds a
perspective of the current working directory. number to give precision in decimal digits. In
4. Identify operators in Python are used to given case, since the number of decimal places
determine whether a value is of a certain class has not been specified, the decimal number is
or type. rounded off to a whole number. Hence, the
output will be 9.
5. lower() is a string function. This function
converts all uppercase letters in string to 18. The lower() function does not modify a string
lowercase letters. in place, it returns a new string which is not
being stored anywhere.
6. List is an ordered sequence, which is used to
store multiple data at the same time. List can 19. Here, max() returns the maximum element in
be created to put the elements in []. the list. From given options, 12454 is the
element with maximum value.
7. Strings are sequence of character data. Strings
are used by programming language to 20. Here i i i i i i ... printed continuously because as
manipulate text such as words and sentences. the value of i or x is not changing, the
condition will always evaluate to True. But
8. List, dictionary and sets are mutable. The values also here we use a quotation marks on “i”, so
of mutable types can be change after it is here i treated as a string, not like a variable.
created.
21. All of the operators shown in given options
9. The process of converting a data type into have associativity from left to right, except
another data type is known as type conversion. exponentiation operator (**) which has its
10. A complex number is a number expressed in associativity from right to left.
the form a + ib, where a (real part) and b 22. Since the first element in the sub-tuple of a is
(imaginary part) are real numbers and i is the larger that the first element in the sub-tuple of
imaginary value.
b, hence False is printed.
11. To print all elements of tuple in reverse order
SAMPLE PAPER 2
https://t.me/cbseexamsweb
66 CBSE Sample Paper Computer Science Class XII (Term I)
number 2 is ‘Hello’ and this will display the 36. The arguments in Python functions may have
elements till (index number − 1) i.e. (4 − 1=3). implicit values. An implicit value is used, if no
So, the correct output is (‘Hello’, 22). value is provided. Here we created a power
function.
27. read(size) method specifies how many
characters the string should return. The function has one argument with an
It reads first 10 bytes and then read some more implicit value. We can call the function with
bytes, i.e. 15 bytes in text file. one or two arguments.
28. In given code, else part is executed if control 37. Here, we define a function called printMax ()
does not break out of the loop and prints 0 to 3. that uses two parameters a and b. We find out
When value of i becomes 4, then flow of the greater number using a simple
current iteration will be terminate and execute if ..else statement and then print the bigger
last print statement. So, correct output is number.
0 38. Values for Lower will be 1, 2, 3 and for Upper
1 will be 2, 3, 4.
2 So, minimum index number is 1 and maximum
3 index number is 4.
Welcome So, output will be among values 30, 40, 50
29. abcd a a a is the output as x is modified only and 60.
after ‘abcd’ has been printed once. 39. The items having indexes from 1 to 4 are
30. for loop starts from 1 and end at 11 with gap of shifted forward by one index due to the first
3 elements. x is a variable, which stores the for loop and the item of index-4 is printed
sum of i iteration. again because of the second for loop.
31. List is a mutable type of object which can be 40. The flush() method flushes the internal buffer.
change after creation. There is list [2, 3, 4] but Python automatically flushes the files when
also mentioned the value of index number 1, so closing them. But you may want to flush the
the value of index number 1. i.e. 3 will be data before closing any file.
replaced with 20. 41. Iteration 1while 9 > 1 : true
So, correct output is [2, 20, 4]. if (9 % 2 == 0) : false
32. dump() method is used to write objects to a else :
file. Before use the dump() method, you first i= 9 −2 = 7
have to import the pickle module. x =7
Syntax pickle.dump(object_to_pickle, prints 49
fileObject) Iteration 2 while 7 > 1 : true
33. This code opens a file “vowel.txt” in read if (7% 2 == 0) : false
mode and check the if condition which will else :
count the vowels. If vowel found, then value of i= 7 −2 = 5
vow increased by 1. x = 5
34. When function Func ( b= 4, a = 5 ) called, then prints 25
a = 5+ 4= 9 Iteration 3 while 5 > 1 : true
b = 4 +1= 5 if (5 % 2 == 0) : false
So, correct output is 9 5 else :
SAMPLE PAPER 2
i= 5 −2 = 3
35. 2*3//4 + 4//4 + 8 − 2 + 5//8
x = 3
= 6 // 4 + 4 // 4 + 8 − 2 + 5 // 8
prints 9
= 1 + 4 // 4 + 8 − 2 + 5 // 8
Iteration 4 while 3 > 1 : true
= 1 + 1 + 8 − 2 + 5 // 8 if (3 % 2 == 0): false
=1+1+8 −2 +0 else:
=2 +8−2 +0 i= 3 −2 = 1
= 10 − 2 + 0 x = 1
=8+0 prints 1
=8
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 67
Iteration 5 while (1 > 1) : false then the new assigned value is reflected
So, output is 49 whenever we use the value of ‘z’ in the main
block or outside the function.
25
48. read() method returns a string containing all
9 characters in a file. So, the data type of s will be
1 string.
42. This code opens a file ‘para.txt’ and read the 49. values () returns a view object that displays a
data word-for-word and len() method is used list of all the values in the dictionary. In given
to find the length or number of bytes. dictionary, ‘One’, ‘Two’, ‘Three’ are keys while
43. It is passing an argument in the form of list 1, 2, 3 are values. So, output is [1, 2, 3].
and for loop is used to iterate the element of 50. The correct option to fill up the blank in line 1
list. is mystr.
return (10/4) mystr is a string, which will be passed during
return (2.5) function calling.
44. This code opens a file ‘Quotes.txt’ and read the 51. count is the correct option to fill up the blank
data word-for-word. It splits the data when in line 2.
space is found. for loop is used to iterate the
word of file. 52. islower () returns true if string has atleast one
case character and all case characters are in
45. In given code, basically find the sum of the lowercase and false otherwise.
values of keys. So, output is 4.
53. i is the correct option to fill up the blank in
46. Any change made in to an immutable data line 4.
type in a function is not reflected outside the
function. So, output is 0. 54. newstr is the correct option to fill up the blank
in line 5.
47. Here in the given code, ‘global’ keyword is
used to state that ‘z’ is global variable. So, 55. makenew is the function’s name which is used
when we assign a value to z in the function to call the function.
SAMPLE PAPER 2
https://t.me/cbseexamsweb
68 CBSE Sample Paper Computer Science Class XII (Term I)
SAMPLE PAPER 3
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
6. ……… operator checks whether the left value is greater than the one on the right.
(a) Greater than or equal to (b) Greater than
(c) Less than or equal to (d) Less than
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 69
15. What will be the output of the following Python code snippet?
d = {“Neha”:140, “Paras”:145}
print(list(d.keys())
(a) [“Neha”, “Paras”] (b) [“Neha”:140, “Paras”:145]
(c) (“Neha”, “Paras”) (d) (“Neha”:140, “Paras”:145)
17. Which one of the following has the same precedence level?
(a) Addition and Subtraction
(b) Multiplication, Division and Addition
(c) Multiplication, Division, Addition and Subtraction
(d) Addition and Multiplication
SAMPLE PAPER 3
https://t.me/cbseexamsweb
70 CBSE Sample Paper Computer Science Class XII (Term I)
25. Which of the following is not a valid attribute of a file object (fp)?
(a) fp.name (b) fp.closed
(c) fp.mode (d) fp.size
Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 71
else:
j = j + 1
print(“m =”, m)
print(“k =”, k)
print(“j =”, j)
(a) m = 2 (b) m = 4 (c) m = 1 (d) m = 2
k=4 k=2 j=2 k=4
j=1 j=1 k=4 j=3
a=[13,6,77]
a.append([87])
a.extend([45,67])
print(a)
(a) [13,6,77, [87], 45, 67] (b) [13,6,77,87,45,67]
(c) [13,6,77,87,[ 45,67]] (d) [13,6,77, [87], [45,67]]
https://t.me/cbseexamsweb
72 CBSE Sample Paper Computer Science Class XII (Term I)
inclusive)
(c) Display details of employees who are earning between 20000 and 40000 (only 20000
inclusive)
(d) Display details of employees who are earning between 20000 and 40000 (only 40000
inclusive)
35. Evaluate the following expression and identify the correct answer.
15 − ( 2 + 7) * 5 + 3 * *2 * 6 − 4 + 2
(a) 18 (b) 20 (c) 22 (d) 35
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 73
36. What will be the output of the following Python code snippet?
a = ‘hello’
for i in range(len(a)):
a[i].upper()
print(a)
(a) hello (b) HELLO
(c) Hello (d) Error
https://t.me/cbseexamsweb
74 CBSE Sample Paper Computer Science Class XII (Term I)
43. Find and write the output of the following Python code.
a=10
def call():
global a
a=15
b=20
print(a)
call()
SAMPLE PAPER 3
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 75
if len(w)<4:
print(w)
file.close()
If the content of file “Story.txt” is
A computer is a machine that can be programmed to carry out
sequences of arithmetic or logical operations automatically.
(a) 9 (b) 10
(c) 19 (d) 11
47. What will be the output of the following Python code snippet?
dic1 = {1:‘One’, 2:‘Two’, 3:‘Three’}
del dic1[1]
dic1[1] = ‘Four’
del dic1[2]
print(len(dic1))
(a) 0
(b) 2
(c) 1
(d) Error as the key-value pair of 1:‘One’ is already deleted
print (s)
f.close()
If the content of file “student.txt” is
Welcome to Arihant!
(a) 20 (b) 18 (c) 19 (d) 17
https://t.me/cbseexamsweb
76 CBSE Sample Paper Computer Science Class XII (Term I)
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
Riya write a program to open a file ‘status.txt’ to read each character and print the
occurrence of alphabets A and N.
def countAN():
f = open(“status.txt”, “r”)
a = 0
n = 0
while ____ : #line 1
l = f.readline( )
if not l :
____ #line 2
for i in ____ : #line 3
if (i = = ‘A’ or i = = ‘a’):
a = + 1
elif (____): #line 4
n = ____ #line 5
print (“A :”, a)
print (“N :”, n)
____ . close () #line 6
51. Choose the correct option to fill the blank in line 2 as marked.
(a) continue (b) break (c) False (d) True
52. Choose the correct option to fill the blank in line 3 as marked.
(a) l (b) f (c) n (d) a
55. Identify the missing code to close the file in line 6 as marked.
(a) l (b) n (c) f (d) file
https://t.me/cbseexamsweb
OMR SHEET SP 3
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
78 CBSE Sample Paper Computer Science Class XII (Term I)
Answers
1. (d) 2. (b) 3. (a) 4. (c) 5. (a) 6. (b) 7. (c) 8. (b) 9. (c) 10. (a)
11. (d) 12. (a) 13. (c) 14. (b) 15. (a) 16. (a) 17. (a) 18. (b) 19. (a) 20. (b)
21. (b) 22. (a) 23. (d) 24. (c) 25. (d) 26. (a) 27. (b) 28. (c) 29. (a) 30. (c)
31. (a) 32. (b) 33. (a) 34. (b) 35. (c) 36. (a) 37. (a) 38. (a) 39. (a) 40. (a)
41. (b) 42. (c) 43. (d) 44. (a) 45. (c) 46. (b) 47. (b) 48. (c) 49. (c) 50. (c)
51. (b) 52. (a) 53. (b) 54. (b) 55. (c)
SOLUTIONS
1. Character set is a set of valid characters that 16. Here is tuple slicing exist. So, a[1:− 1] returns
represents any digit, alphabet and special (12,13).
symbol.
17. “Addition and Subtraction” are at the same
2. Literals are the most obvious kind of constants precedence level. Similarly, “Multiplication
that refer to fixed values which may not alter and Division” are at the same precedence level.
during execution of program. However, ‘‘Multiplication’’ and ‘‘Division’’
3. Logical operators are used to make a decision operators are at a higher precedence level than
on two conditions. These are typically used ‘‘Addition’’ and ‘‘Subtraction’’ operators.
with boolean values.
18. The given expression is an example of explicit
4. String literals in Python are enclosed by single conversion. It is evaluated as int(43.55+ 1) =
and double quotes. int(44.55) = 44. Hence, the result of this
5. −1 index number is used to represent last expression is 44.
character of string. 19. round () returns a floating point number that is
6. Greater than operator checks whether the left rounded version of the specified number.
value is greater than the one on the right. Syntax round (number,digit)
7. file.mode attribute is used to return access So,round (65.8) will run with error.
mode in which file was opened. 20. The term “module” refers to the
8. write() method takes a string and writes it in implementation of specific functionality to be
the file. This method does not add a newline incorporated into a program.
character to the end of the string. 21. During a Python program execution, there are
9. For readline(), a line is terminated by \n (new as many as three namespaces–built-in
line) and EOF (End of File). namespace, global namespace and local
namespace. So, public is not a valid
10. Serialization process is called pickling. Pickling namespace.
is way to convey a Python object into a
character stream. 22. The tell() method tells you the current position
within the file; in other words, the next read or
11. x is a access mode.This character is used to write will occur at that many bytes from the
create a new file in CSV.
beginning of the file.
12. A relative path is a path that is relative to the
23. Mode meaning is as explained below:
working directory location on your computer.
SAMPLE PAPER 3
15. The output of the code is a list containing only 24. The method writelines() writes a sequence of
keys of the dictionary d, with the help of strings to the file. The sequence can be any
d.keys () method. iterable object producing strings, typically a
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 79
https://t.me/cbseexamsweb
80 CBSE Sample Paper Computer Science Class XII (Term I)
42. Iteration 1 if (0% 4 = = 0) : true 47. After the key-value pair of 1:‘One‘ is deleted,
prints 0 the key-value pair of 1:‘Four’ is added.
Iteration 2 if (1% 4 == 0) : true Then key-value pair of 2: ‘Two’ is deleted.
prints 4 So, length of present dictionary will be 2.
Iteration 3 if (2% 4==0) : false
48. This code opens the file ‘student.txt’ in read
prints 5 mode and read the data word-to-word.
Iteration 4 if (3% 4==0) : false
It will find the length of file.
prints 6
49. t1 is a tuple in which [1, 2] is a nested tuple. t1
Iteration 5 if (4% 4==0) : true
[2] [1] represents the second element of nested
prints 16
tuple, which will replaced by 11.
So, output is 0
50. Correct option to satisfy while condition is
4
True.
5
51. When if condition becomes true, then it will
6
terminate with break statement.
16
52. for loop will be iterate till l, which stores the
43. When function call() will be called, then value data of file ‘status. txt’ line-by-line.
of ‘a’ prints 15 which defined as global.
53. According to question, print occurrence of
44. This program opens a file ‘STORY.TXT’ in read alphabets A and N, condition for A is already
mode. It counts those words whose length less given in if, so we will use condition for N in
than 4 because here is a condition len(w)<4. elif .
45. In given code, the copy is a type of shallow 54. Value of n will be incremented by one, when
copy and only changes made in sub-list is elif condition becomes true.
reflected in the copied list, which replaced 73
by 110. 55. To close the file, syntax is
fileobject.close()
46. In the piece of code, slice assignment has been
implemented. The sliced list is replaced by the In given code, fileobject is f, so missing code
assigned elements in the list. will be f.
SAMPLE PAPER 3
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 81
SAMPLE PAPER 4
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
1. Which function returns the value for the given key, if key is present in the dictionary?
(a) items() (b) get()
(c) clear() (d) keys()
3. All the errors that are detected and displaced by the compiler or interpreter are
known as
SAMPLE PAPER 4
https://t.me/cbseexamsweb
82 CBSE Sample Paper Computer Science Class XII (Term I)
10. What is the minimum number of iterations that while loop could make?
(a) 1 (b) 2 (c) − 1 (d) 0
13. Riya intends to position the file pointer to the beginning of a text file. Identify the
Python statement for the same assuming F is the FileObject.
(a) F.load(0) (b) F.dump(0) (c) F.seek(0) (d) F.pickle()
16. To read the entire remaining contents of the file as a string from a file object f, we use
……… .
(a) f.read(5) (b) f.read()
(c) f.readline() (d) f.readlines()
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 83
20. Read the following Python code carefully and point out the global variables?
a, b = 25,12
def test():
global i
i = a+b
(a) i (b) a and b
(c) i, a and b (d) Neither i nor a nor b
Section B
SAMPLE PAPER 4
26. Which of the following statement opens a binary file ‘test.bin’ in write mode and writes
data from a tuple t1=(2, 5, 8, 2) on the binary file?
(a) with open(‘test.bin’,‘wb’)as f:
pickle.dump(t1, f)
(b) with open(‘test.bin’,‘wb’)as f:
pickle.dump(f,t1)
https://t.me/cbseexamsweb
84 CBSE Sample Paper Computer Science Class XII (Term I)
31. What will be the output of the following Python code snippet?
N1 = {}
SAMPLE PAPER 4
N2 = {}
N3 = {}
n1[1] = 6
n1[3] = 7
n2[4] = ‘B’
n3[‘Numbers’] = n1
n3[‘Letters’] = n2
print(n3)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 85
32. What will be the output of the following Python code snippet?
x =‘pqrs’
for i in range(len(x)):
x = ‘p’
print(x)
(a) p (b) pqrspqrspqrs
(c) pppp (d) Error
33. Choose the correct option from the following, when program will be run.
myfile = open(“story.txt”, “rw+”)
for index in range(5):
line = myfile.next( )
print(“Line No %d %s” % (index, line))
myfile.close( )
(a) It gives compilation error (b) It gives syntax error
(c) It displays output (d) None of the mentioned
str1=“Hello Arihant”
cn=0
for i in str1:
cn=cn+1
new=str1[0:2]+str1[cn−2:cn]
print(new)
(a) Helo (b) Arnt (c) Hello (d) Hent
https://t.me/cbseexamsweb
86 CBSE Sample Paper Computer Science Class XII (Term I)
40. Riya is working on file handling in which her file’s working directory is Users\Arihant
in drive C. Identify the output of following code snippet.
import os
s=os.getcwd( )
print(“%s”, s)
(a) C:\Arihant (b) C:\Users\Arihant
(c) D:\Arihant (d) D:\Users\Arihant
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 87
45. What will be the output of the following Python code snippet?
dic1 = {1:‘One’, 2:‘Two’, 3:‘Three’}
dic1 = {}
print(len(dic1))
(a) 1 (b) 0 (c) 3 (d) 2
f.close( )
(a) 25 (b) 23 (c) 22 (d) 26
https://t.me/cbseexamsweb
88 CBSE Sample Paper Computer Science Class XII (Term I)
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
import os
def countopen():
if os.path.isfile(“start.txt”):
______=open(“start.txt”,“r”) # line 1
c=0
print(“The lines are:”)
while True:
l=f.______() # line 2
l=l.______() # line 3
print (l)
if not l:
______ # line 4
list1=l.upper().split()
if(list1[0]______ ‘OPEN’): # line 5
c=c+1
if(______): # line 6
print(“Total lines started with
the word ‘OPEN’ is/are:”,c)
else:
print(“There is no line started
with the word ‘OPEN’ ”)
f.close()
else:
print(“File does not exist”
50. Choose the correct option to fill up the blank in line 1 as marked
(a) l (b) f (c) r (d) c
51. Choose the correct option to fill up the blank in line 2 as marked
(a) read () (b) read (n) (c) redline () (d) readlines ()
52. Choose the correct option to fill up the blank in line 3 as marked
SAMPLE PAPER 4
53. Identify the missing statement to fill up the blank in line 4 as marked
(a) continue (b) break (c) flag (d) label
54. Choose the correct option to fill up the blank in line 5 as marked
(a) i = (b) > = 0 (c) < = 0 (d) = =
https://t.me/cbseexamsweb
OMR SHEET SP 4
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
90 CBSE Sample Paper Computer Science Class XII (Term I)
Answers
1. (b) 2. (a) 3. (b) 4. (d) 5. (a) 6. (d) 7. (a) 8. (d) 9. (b) 10. (d)
11. (a) 12. (d) 13. (c) 14. (c) 15. (a) 16. (b) 17. (a) 18. (b) 19. (c) 20. (c)
21. (a) 22. (a) 23. (d) 24. (a) 25. (d) 26. (a) 27. (c) 28. (a) 29. (a) 30. (a)
31. (a) 32. (c) 33. (c) 34. (b) 35. (c) 36. (d) 37. (d) 38. (a) 39. (c) 40. (b)
41. (b) 42. (b) 43. (c) 44. (a) 45. (b) 46. (b) 47. (a) 48. (c) 49. (c) 50. (b)
51. (c) 52. (c) 53. (b) 54. (d) 55. (c)
SOLUTIONS
1. get() function returns the value for the given takes three arguments, they are evaluated as
key, if key is present in the dictionary. (x**y)%z.
Syntax dictionary_name.get(key[,value]) 15. The first function will result in an error
2. To create a dictionary in Python, key : value because the function sum() is used to find the
pair is used. sum of iterable numbers. Hence, the outcomes
will be Error and 17, respectively.
3. All the errors that are detected and displaced
by the compiler or interpreter are known as 16. read () function is used to read all the content
compile-time errors. in a file.
4. Syntax errors occur when syntax rules of any 17. split() function returns the elements in a list.
programming language are violated. Common 18. A tuple of one element must be created as (1).
Python syntax errors are leaving out a
keyword, misspelling a keyword, incorrect 19. Pickling is the process of serializing a Python
object, i.e. conversion of a byte stream into
indentation, etc.
Python object hierarchy. The reverse of this
5. The collection of functions creates a program. process is known as unpickling.
A function can be defined as the organised
20. In the given code, i, a and b are global
block of reusable code, which can be called
variables inside the function test. a and b are
whenever required
global because they are not assigned in the
6. Built-in functions are pre-defined functions in function. i is a global variable because it is
Python programming system that are always explicitly specified in the code. Hence, i, a and
available for use. b are global variables.
e.g. type(), input(), print(), etc. 21. Type conversion is nothing but explicit
7. range() function is used to generate a sequence conversion of operands to a specific type.
of numbers overtime. Options (b) and (c) are examples of implicit
8. Iterative statements enable a program with a conversion whereas option (a) is an example of
cyclic flow of logic. explicit conversion or type conversion.
22. The istitle() method returns True, if all words
9. num=4+3.5 = 7.5 in a text start with a upper case letter and the
10. while loop could make minimum 0 iteration. rest of the words are lower case letter,
11. There is no element in () that it is an empty list. otherwise False.
Empty list is represented by []. 23. It will give an error because + operator cannot
SAMPLE PAPER 4
12. In Python, tuple() method is used to convert add list with other type as number or string.
string and list into tuple. 24. for statement encloses one or more statements
13. F. seek(0) is used for this condition. This that form the body of the loop, the statements
method can be used to change the current in the loop repeat continuously a certain
position in a file. This method does not return number of times.
any value. Syntax for variable in range (start, stop):
14. The built-in function pow() can accept two or To repeat 100 times, the for will be
three arguments. When it takes two for i in range (0, 100):
arguments, they are evaluated as x**y. When it or
for i in range (1, 101):
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 91
25. This code gives TypeError because cannot 37. f.seek(−3, 2) positions the FileObject to 3
multiply sequence by non-int of type ‘tuple’. bytes before end of file.
26. After open the file ‘test.bin’ in write mode, to So, output of statement 2 is de.
write the data to that file following code is used 38. Minimum value and maximum value are 0
with open(‘test.bin’,‘wb’) as f : and 3, respectively. So, output should be in
pickle.dump (t1,f) numbers between 0 and 3.
27. Iteration1 while (90 > 60): true 39. The called function passes two values n1 and
prints 90 n2 whose values are 23 and 2 respectively,
these correspond to the parameters a and b,
w=90−40=50
declared for the function test( ).
Iteration 2 while (50 > 60): false
It performs x=23*2=46. So, output is 46.
So, output is 90.
40. getcwd( ) method returns the current
28. Variable val has a list which contains two
working directory of a process.
sub-lists. First for loop goes from i to length of
list val. Second for loop goes from j to i, then 41. It accepts list L as an argument and convert
check the if condition. all the odd numbers into even by multiplying
to 2.
29. The value passed to the function test() is 25. This
value is incremented by one and printed. Hence, 42. It prints numbers from 1 till while condition
the output of the given code is 26. is true. The else part is executed when the
condition in the while statement is false.
30. A new list object is created in the function and
the reference is lost. This can be checked by 43. slice() is used to give the elements from tuple
comparing the id of x before and after x = [5]. or list.
So, the output is [1]. 44. The given code is used to convert a
temperature in degree celsius to fahrenheit.
31. Dictionary in a dictionary can exist.
45. In the second line of code, the dictionary
For key ‘Numbers’, value is {1:6, 3:7} and for key
becomes an empty dictionary. Thus,
‘Letters’, value is {4:‘B’}.
length=0.
So, final output is
46. any( ) method returns True if atleast one
{Numbers’ :{1:6, 3:7}, ‘Letters’ : {4:‘B’}}.
element is present in the tuple,otherwise
32. This program prints pppp because for loop will returns False.
excute till length of x, i.e. 4.
47. It opens file ‘‘para.txt’’ in read mode and
33. The next() method is used when a file is used as read the data word-for-word and print the
an iterator, typically in a loop, the next() method length of file.
is called repeatedly. This method returns the
48. c=a/b= a/0 will generate the run-time error as
next input line or raises StopIteration when EOF
division by zero.
is hit.
49. It gives the error as index out of range
34. A = 3* 4// 5+ 5 // 7+ 8 − 2 + 4 // 2
because list [3] [2] does not exist in given list.
= 12 // 5+ 5 // 7+ 8 − 2+ 4 // 2
= 2 + 5 // 7+ 8 − 2 + 4 // 2 50. f is the file object that is used to read and
= 2 + 0 + 8 − 2 + 4 // 2 write data to a file on disk.
= 2 + 0 + 8 − 2 + 2 =2 + 0 + 6 + 2 51. readline () method will read from a file line
Α = 10 by line.
SAMPLE PAPER 4
35. Iteration 1 while (123>3) : true 52. rstrip () returns a copy of the string with
rem=123%100=23 trailing characters removed. If no argument
if(23%2!=0) : true is passed, it removes trailing spaces.
f=0+23=23 53. break statement alters the normal flow of
num=123/100 = 1 execution as it terminates the current loop
Iteration 2 while (1>3) : false and resumes execution of the statement
following that loop.
prints 23
54. = = (equal to) is used in if condition in line 5.
36. This program will form a new string made of the
first two and last two characters from a given 55. c > 0 is used to fill up the blank in the if
string. condition.
https://t.me/cbseexamsweb
92 CBSE Sample Paper Computer Science Class XII (Term I)
SAMPLE PAPER 5
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
3. This method is used to delete key and respective value from dictionary.
(a) del() (b) delete() (c) pop() (d) remove()
4. Which of the following errors will result the abnormal termination of program?
(a) Run-time (b) Compile-time (c) Semantic (d) Syntax
SAMPLE PAPER 5
5. Which exception classes raised when a generated error does not fall into any category?
(a) RuntimeError (b) TypeError (c) KeyError (d) AttributeError
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 93
11. Which access mode can be used for opening a file for both appending and reading in a
text file?
(a) a (b) a+ (c) r (d) r+
14. Which one of the following has the highest precedence in the expression?
(a) Exponential (b) Addition (c) Multiplication (d) Parenthesis
15. Which are the two built-in functions to read a line of text from standard input, which
by default comes from the keyboard?
(a) raw_input() and input() (b) input() and scan()
(c) scan() and scanner() (d) scanner()
17. What will be the output of the following Python code snippet?
d1 = {“Siya”:86, “Naman”:75}
SAMPLE PAPER 5
d2 = {“Siya”:99, “Naman”:75}
d1 == d2
(a) True (b) False (c) None (d) Error
https://t.me/cbseexamsweb
94 CBSE Sample Paper Computer Science Class XII (Term I)
22. Observe the following code and identify the type of file.
File=open(“Mydata”, “a”)
File.write(“ABC”)
File.close()
(a) Binary file (b) CSV file
(c) Text file (d) None of these
23. Consider the declaration a=[2, 3, ‘Hello’, 23.0]. Which of the following represents the
data type of ‘a’?
(a) string (b) tuple (c) dictionary (d) list
Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
SAMPLE PAPER 5
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 95
32. Siya is trying to write a list l1=[2, 5, 4, 3] on a binary file ‘hello.bin’. Consider the
following code written by her.
import pickle
l1=[2, 5, 4, 3]
f=open (“hello.bin”,‘wb’)
SAMPLE PAPER 5
https://t.me/cbseexamsweb
96 CBSE Sample Paper Computer Science Class XII (Term I)
x = x[:− 1]
print(i, end = “”)
(a) i i i i i i (b) a a a a a a
(c) a a a a a (d) None of the mentioned
38. Evaluate the following expression and identify the correct answer.
25 + ( 6 − 4) * 2 + 4 / /3 * 4 − 1
(a) 32 (b) 42 (c) 22 (d) 33
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 97
print(i)
(a) 11 12 13 (b) {11, 12, 13} {11, 12, 13} {11, 12, 13}
(c) Error (d) None
https://t.me/cbseexamsweb
98 CBSE Sample Paper Computer Science Class XII (Term I)
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
Riya wrote a program to search any string in text file “school”. Help her to execute the
program successfully.
def check() :
datafile = open (_______) #Line 2
found = input(“Enter any string to be searched : ”)
f = False
for line in _______ : #Line 5
SAMPLE PAPER 5
if found in line :
f = _______ #Line 7
_______ #Line 8
return f
f = check ()
if(f = = _______) : #Line 11
print (“True”)
else :
print (_______) #Line 14
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 99
54. Choose the correct option to fill up the blank in Line 11.
(a) 0 (b) 1 (c) False (d) True
SAMPLE PAPER 5
https://t.me/cbseexamsweb
OMR SHEET SP 5
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 101
Answers
1. (a) 2. (d) 3. (c) 4. (a) 5. (a) 6. (a) 7. (c) 8. (b) 9. (d) 10. (a)
11. (b) 12. (d) 13. (a) 14. (d) 15. (a) 16. (a) 17. (b) 18. (a) 19. (c) 20. (c)
21. (b) 22. (c) 23. (d) 24. (a) 25. (c) 26. (b) 27. (a) 28. (a) 29. (b) 30. (c)
31. (b) 32. (b) 33. (b) 34. (d) 35. (a) 36. (c) 37. (a) 38. (a) 39. (b) 40. (d)
41. (b) 42. (c) 43. (b) 44. (a) 45. (c) 46. (a) 47. (c) 48. (b) 49. (b) 50. (b)
51. (c) 52. (d) 53. (a) 54. (d) 55. (b)
SOLUTIONS
1. Each key value pair in a dictionary is separated 15. Python provides two built-in functions to read
by a : (colon). a line of text from standard input, which by
2. Dictionary is an unordered collection of data default comes from the keyboard. These
values that store the key : value pair instead of functions are raw_input() and input().
single value as an element. 16. range(1, int(3.0)) is the same as range(1, 3).
Dictionaries are also called mappings, hashes So, it will print 1
and associative arrays. 2
3. pop() method is used to delete key and 17. If d2 was initialized as d2 = d1 the answer
respective value from dictionary. would be False.
4. Run-time errors will result the abnormal 18. Here, ‘a’ is used to indicate that data is to be
termination of program. appended.
5. RuntimeError exception classes raised when a 19. The result of an expression int(1101,2) is given
generated error does not fall into any category. an error. Had we written this expression as
6. a+10*2+b = 10 + 10 * 2 + 2 int(‘1101’,2), then there would not be an error.
= 10 + 20 + 2 20. Tuple does not have any update() attribute
= 30 + 2 = 32 because it is immutable and cannot be changed
7. Keywords are pre-defined reserved words that after creation.
have some special or pre-defined meanings. 21. 1st_number is an invalid variable name.
while is an example of keyword. Because variable names should not start with a
8. User can also add elements into an empty number.
dictionary by 22. If file extension is not mentioned with file
dictionary_name [key]=value name, then it would be text file by default.
9. It will give TypeError because integer and 23. List contains a sequence of heterogeneous
string cannot be concatenate. elements which store integer, string as well as
object. It can created to put elements separated
10. A complex number is a number expressed in by comma (,) in square brackets [].
the form a+ib or a+jb, where a and b are real
numbers and i is the imaginary number. 24. del keyword is used to delete the elements
from the list.
11. a+ access mode can be used for opening a file
SAMPLE PAPER 5
for both appending and reading in a text file. 25. keys() returns a view object that displays a list
of all the keys in the dictionary.
12. read(6) method specifies 6 characters the string
should return. In given dictionary, A, B, C are keys, while
One, Two, Three are values.
13. To display elements from beginning to a range
use [: index]. 26. This program will find all such numbers which
are divisible by 7 but are not a multiple of 5,
14. Just remember: PEMDAS, i.e. Parenthesis, between 20 and 40 (both included).
Exponentiation, Division, Multiplication,
Addition, Subtraction. Hence, from this rule 27. This program is passing a string to function
‘Parenthesis’ has the highest precedence in the and print a character of string one-by-one.
expression.
https://t.me/cbseexamsweb
102 CBSE Sample Paper Computer Science Class XII (Term I)
28. x is a list which has two sub-lists in it. Elements of 39. When function work() called, then
first list will be represented by [0] [i] and elements s = 23 + 62
of second list will be represented by [1] [i]. s = 85
29. When we will call a function fun(), then argument 40. The expected value of N will be 1, 2, 3.
of this function ‘World’ performs World *2, i.e. So, for loop will go maximum limit 3.
World World.
41. This program opens a file ‘‘para.txt’’ in read
30. In given program, ‘a’ is global variable and c is mode. It will read those lines which are not
local variable. Global variable is accessible start with character ‘W’.
throughout the program. So, c =10+5=15.
42. f.seek (4, 3) positions the FileObject to 5
31. This program will remove the characters of odd bytes from the starting of the file content.
index number in a string and display the
characters of even index number in a string. So, output is efg.
32. dump() method is used to write objects to a file. 43. Lists are provide slice steps which used to
extract elements from list that are not
Syntax pickle.dump(object_to_pickle, consecutive.
FileObject) Syntax
33. The string x is being shortened by one character in s=list_name [start : stop : step]
each iteration.
44. Loops over the elements of the set and
34. In the given code, when we call the function test prints these elements.
(), a new namespace is created. The assignment
a=25 is performed in the local namespace and does 45. The value of ‘x’ can be changed by using
not affect the global namespace. Hence, the output globals() function.
is 5. So, value of x = 15 replaced by 63.
35. The first time that we print the value of the name 46. read () method returns a string containing
‘a’ with the first line in the function’s body, all characters in a file.
Python uses the value of the parameter declared 47. return num is used to fill up the blank in
in the main block, above the function definition. Statement 1.
Next, we assign the value 5 to a. The name ‘a’ is
local to this function. So, when we change the value 48. * operator is used to replicate the tuple.
of ‘a’ in the function, the ‘a’ defined in the main So, output is (3, 4, (6, 1), 7, 3, 4, (6, 1), 7).
block remains unaffected. 49. Line 2 has an error becasue colon (:) will be
With the last print() function call, we display the used in while statement.
value of ‘a’ as defined in the main block, thereby So, correct statement in Line 2 is
confirming that it is actually unaffected by the
while (i < 25) :
local assignment within the previously called
function. 50. Riya should open ‘‘school.txt’’ file to search
any string. File name is given in question
36. split () function splits the string in number of
without its file extension that means file
times given as the second argument but without
will be text file. Because by default the
separator
extension of file is text file.
Here, 2 is given as second argument so string will
be split at index number 2. 51. datafile is used to fill up the blank in Line 5.
Then , output is [‘H#E’, ‘L#L#O’]. 52. The value True will be assign to f in Line 7.
SAMPLE PAPER 5
37. The ‘with’ statement when used with open file 53. break statement is the correct option to fill
guarantees that the file object is closed when the
up the blank in Line 8.
with block exist.
54. True is the correct option to fill up the
38. 25 + (6 − 4 ) * 2 + 4 / /3 * 4 − 1
blank in Line 11, which will satisfy the if
= 25 + (6 − 4 )*2 + 1 * 4 − 1 condition.
= 25 + (2 ) * 2 + 1 * 4 − 1
55. “False” as a string will be print by last line
= 25 + 4 + 1 * 4 − 1 = 25 + 4 + 4 − 1 when if condition becomes false and else
= 25 + 4 + 3 = 25 + 7 = 32 part executed.
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 103
SAMPLE PAPER 6
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
2. Consider the declaration a= {1: ‘A’, 2: ‘B’}, which of the following represents the data
type of a?
(a) list (b) dictionary (c) tuple (d) string
https://t.me/cbseexamsweb
104 CBSE Sample Paper Computer Science Class XII (Term I)
7. Which of the following method tells you the current position within the file?
(a) dump() (b) load() (c) tell() (d) seek()
10. This namespace includes names from various imported modules that you are using in
a project.
(a) Built-in (b) Local (c) Global (d) None of these
11. Identify the options and choose which option has an error.
(a) print(‘Hello’ *4) (b) print(‘Hello’ +‘4’)
(c) print(2*‘R’) (d) print(‘Hello’*‘4’)
12. Each individual character in a string can be accessed using a technique called
(a) traversing (b) indexing
(c) sequencing (d) slicing
all(5,1,3.5)
(a) True (b) False (c) Error (d) None
18. A function that does not return any value, then what value is thrown by default when
this function will be execute?
(a) int (b) bool (c) void (d) None
19. Operators with the same precedence are evaluated in which manner?
(a) Left to Right (b) Right to Left
(c) Cannot say (d) None of the mentioned
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 105
22. Which of the following files are used to store a large number of variables or data?
(a) Text files (b) CSV files
(c) Binary files (d) Data files
Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
https://t.me/cbseexamsweb
106 CBSE Sample Paper Computer Science Class XII (Term I)
hello hello
honesty honesty
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 107
35. Evaluate the following expression and identify the correct answer.
2 + ( 4 − 1) * 3 / /2 + 7 * 3 + 10 / /3 − 2
(a) 28 (b) 22 (c) 24 (d) 32
if i%5 == 0 :
break
print(i)
i += 1
(a) 1 (b) 0 (c) 0 (d) 1
2 1 1 2
3 2 2 3
4 3 3 4
4 5
https://t.me/cbseexamsweb
108 CBSE Sample Paper Computer Science Class XII (Term I)
(a) 4 (b) 2
(c) 6 (d) 7
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 109
(c) (‘T’ ‘U’ ‘P’ ‘L’ ‘E’) (d) (‘T’, ‘U’, ‘P’, ‘L’, ‘E’)
https://t.me/cbseexamsweb
110 CBSE Sample Paper Computer Science Class XII (Term I)
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
Below is a program to enter a string and display new string. Answer the questions that
follow to execute the program successfully.
def make (str1) :
newstr = “ ”
count = 0
for i in str1:
if count % 2 ___0: # Statement 1
newstr=newstr+str(count)
else :
if islower(___) : # Statement 2
newstr=newstr + upper ___ # Statement 3
else :
newstr=newstr+ i
count = ___ # Statement 4
newstr=___ + str1[: 1] # Statement 5
print (___) # Statement 6
make(“aRiHaNT”)
https://t.me/cbseexamsweb
OMR SHEET SP 6
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
112 CBSE Sample Paper Computer Science Class XII (Term I)
Answers
1. (c) 2. (b) 3. (b) 4. (d) 5. (a) 6. (b) 7. (c) 8. (d) 9. (b) 10. (c)
11. (d) 12. (b) 13. (b) 14. (a) 15. (d) 16. (d) 17. (c) 18. (d) 19. (a) 20. (a)
21. (d) 22. (b) 23. (c) 24. (b) 25. (a) 26. (a) 27. (b) 28. (b) 29. (b) 30. (d)
31. (a) 32. (d) 33. (a) 34. (c) 35. (a) 36. (a) 37. (a) 38. (b) 39. (c) 40. (b)
41. (c) 42. (a) 43. (d) 44. (d) 45. (b) 46. (a) 47. (d) 48. (a) 49. (c) 50. (d)
51. (b) 52. (a) 53. (c) 54. (b) 55. (c)
SOLUTIONS
1. jump statements allow altering the flow of a 12. Each individual character in a string can be
program by performing jumps to specific accessed using a technique called indexing.The
locations. break and continue are jump index specifies the character to be accessed in
statements. the string.
2. Dictionary is an unordered collection of data 13. Tuple concatenation is the technique of
values that store the key : value pair instead of combining two tuples. To concatenate tuples, +
single value as an element. operator is used in Python.
3. is not operator returns True, if both the 14. A variable that is defined inside any function
operands point to different memory location. or a block is known as a local variable.
In given code, ‘a’ and str point different 15. wb+ is an access mode which opens a file for
memory so its output is True. both writing and reading in binary format.
4. dump() is used to write objects to a binary file. Overwrites the file if the file exists. If the file
It is provided by pickle module. does not exist, it creates a new file for reading
Syntax pickle.dump(object_to_pickle, and writing.
FileObject) 16. Variable declared outside of all functions in a
5. sys. stderr stands for standard error. This file program has global scope and is known as
object is used for error message only, even global variable. These are useful for all the
though its output goes for same destination as functions.
stdout. 17. The function all() returns ‘True’ if any one or
6. To read data from CSV files, you must use the more of the elements of the iterable are
reader() function to generate a reader object. non -zero. In the given case, the values are not
iterable, hence an error is thrown.
7. tell() method tells you the current position
within the file, measured in bytes from the 18. Python shell throws a NoneType object.
beginning of the file. 19. Operators with the same precedence are
evaluated from left to right.
8. There is a colon (:) at the end of def line. Then,
the indented statements form the body of 20. The expansion of EOL is End of Line. It is used
function. for terminated a line.
9. Parameter is a variable used to define a 21. readlines() method will return a list of strings,
particular value during a function definition. each separated by ‘\n’.
SAMPLE PAPER 6
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 113
25. The range() function is used to generate a 36. if (18% 5==0) : False
sequence of numbers overtime. else:
There is 5 in parenthesis of range, i.e. numbers x=x-num=28-18=10
prints 20 #
0 to 4 will be display.
function output() calls
26. Iteration 1 for A in dic: true prints 10
res=1*5=5 So, output is 20#10.
Iteration 2 for B in dic: true 37. Control exits the loop when i becomes 5.
res=5*3=15
So, it prints the number 1 to 4 i.e. 1
Iteration 3 for C in dic: true
2
res=15*2=30
3
27. The string ‘a’ is being shortened by one 4
character in each iteration which display ‘K’.
38. test() is a function in which a list is passed. In
So, output is K.
passed list, elements are appended.
28. Since a list is mutable, any change made in the
39. In the given code, i=8 is a local variable
list in the function is reflected outside the
whereas i=15 is a global variable.
function.
Preference is given to local variable over global
After calling the function, output is 5.
variable. Hence, the output is 8.
29. It is possible to read the value of a global
40. Both print statements display same value, so
variable directly.
the value of n will be 77.
When test() is called, it will return 0+1=1.
41. dic is a dictionary whose values are given and
So, output is 1. sum is a variable which will store the sum of
30. The program opens a file and reads the value of dictionary.
contents of the file in reverse order. In dictionary dic, 1 and 1.0 are keys while 2
31. This program reads a file and capitalises the and 4 are values.
first letter of every word in the file. So, the output is 6 [sum of values].
32. dic1() function is passing a dictionary and 42. Value of t[1] is 0 because index number is 1
displays them in separate file. and value of t[ −2 ] is 34 because index number
So, output is 1 : A is started from −1 at the end point. t1 will store
the sum of both values, i.e. 0+34=34.
2:B
43. Iteration 1 while (5 > 0 ):true
3:C
f=1*5=5
33. A function test (x) displays the element in
n=5−1=4
reverse order such that each displayed element
is the twice of the original element of the List x. Iteration 2 while (4 > 0) : true
So, output is [20, 4, 12, 10, 14, 16, 8] f =5*4 =20
n=4−1=3
34. test() is a function which performs subtraction.
Iteration 3 while (3 > 0):true
But, test= test (53, 40) will not print any output.
f=20*3=60
35. 2 + ( 4 − 1) * 3 / /2 + 7 * 3 + 10 / /3 − 2 n=3−1=2
=2 + 3 * 3 / /2 + 7 * 3 + 10 / /3 − 2 Iteration 4 while (2>0) : true
SAMPLE PAPER 6
=2 + 9 / /2 + 7 * 3 + 10 / /3 − 2 f=60*2=120
=2 + 4 + 7 * 3 + 10 / /3 − 2 n=2−1=1
=2 + 4 + 7 *3 + 3 − 2 Iteration 5 while (1 > 0):true
=2 + 4 + 21 + 3 − 2 f=120*1=120
=2 + 4 + 21 + 1 n=1−1=0
=2 + 4 + 22 Iteration 6 while (0>0):false
https://t.me/cbseexamsweb
114 CBSE Sample Paper Computer Science Class XII (Term I)
44. This code will give an error because ‘>’ (max) 50. ! = is the correct option that used in Statement
not supported between instances of ‘str’ and 1, which will help to check the if condition. It is
‘int’. not equal to operator.
45. It will give the output as float type which adds 51. i will come in function islower() in Statement 2.
int and float, i.e. 3+1.6=4.6 islower() checks the string is in lowercase or
46. readlines () method will return a list of strings, not.
each separated by ‘\n’. 52. i is the correct option to fill up the blank in
47. tuple() method is used to create a tuple from Statement 3. upper(i) converts the lowercase
an existing sequence or string. letters in string to uppercase.
48. del keyword is used to delete the key with its 53. count +1 will be assign to variable count in
respective value that is present in the Statement 4.
dictionary. 54. newstr is the correct option to fill up the blank
49. It opens a file ‘‘test.txt’’ and read the data in Statement 5.
character-by-character and display the length 55. newstr is the correct option to fill up the blank
of file with the help of len() method. in Statement 6.
SAMPLE PAPER 6
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 115
SAMPLE PAPER 7
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
2. Consider a declaration s = ‘‘computer’’, which of the following represents the data type
of s?
(a) list (b) tuple (c) dictionary (d) string
3. Given a list L1 = [3, 4, 5, 6, 8, 7, 7, 1, 2], what will be the output of print (L1 [3 : 7 : 2])?
(a) [6, 8, 7, 7, 1] (b) [6, 8, 7, 7]
(c) [6, 7] (d) (6, 7)
4. Which of the following is a path that contains the entire path to the file?
SAMPLE PAPER 7
5. Which of the following option can be used to read the 5 bytes of text file ‘‘Para.txt’’?
(a) f = open(“Para.txt”) (b) f = open(“Para.txt”)
f.read( ) = 5 f.read(5)
(c) f = open (“Para.txt”) (d) f = open(“Para.txt”)
f.readline(5) f.readlines(5)
https://t.me/cbseexamsweb
116 CBSE Sample Paper Computer Science Class XII (Term I)
6. Assume f is file object and to change the current position of file to 3 bytes forward.
Which statement will be used?
(a) f.seek(3, 1) (b) f.seek(1, 3)
(c) f.tell(3, 1) (d) f.tell(1, 3)
9. Which of the following loop is used for fixed number of iterations in Python?
(a) while loop (b) for loop
(c) do while loop (d) All of these
10. Consider the tuple t = (3, 4, 5, 8, 2). Identify the statement that will result in an error.
(a) print(t [1]) (b) t[3] = 9
(c) print(min(t)) (d) print(len(t))
11. Identify the category of the function that contains those functions which provide the
facility for doing some pre-defined operations.
(a) Built-in function (b) Library function
(c) Both (a) and (b) (d) None of these
14. Which type of the argument need to be included in the proper position?
(a) Default argument (b) Name argument
(c) Positional argument (d) Friendly argument
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 117
20. In order to store values in terms of keys what basic data type can be used?
(a) List (b) Tuple
(c) String (d) Dictionary
22. What happens, if a local variable exists with the same name as the global variable you
want to access?
(a) Error
(b) The local variable is shadowed
(c) Undefined behavior
(d) The global variable is shadowed
24. Which type of data file stores the data in tabular form?
SAMPLE PAPER 7
https://t.me/cbseexamsweb
118 CBSE Sample Paper Computer Science Class XII (Term I)
Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
(a) 4 (b) 9
(c) 12 (d) 23
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 119
32. Naman is trying to write a tuple tup1 = (5, 3, 4, 3) on a binary file ‘‘story.bin’’. Consider
the following code written by him.
import pickle
tup1 = (5, 3, 4, 3)
f = open(“story.bin”, ‘wb’)
pickle. _____ # Statement 1
f. close( )
Identify the missing code in Statement 1.
(a) dump (f,tup1) (b) dump (tup1, f)
(c) write (tup1,f) (d) load (f,tup1)
33. Evaluate the following expression and identify the correct answer.
10*4 // 2 + 4 − 2 //2 + 4 − 3 + 5 // 8
(a) 24 (b) 34 (c) 22 (d) 20
(a) 2 3 4 5 6 1 (b) 6 1 2 3 4 5
(c) 4 9 6 2 3 3 (d) 4 4 2 9 6 3
https://t.me/cbseexamsweb
120 CBSE Sample Paper Computer Science Class XII (Term I)
test()
print(a)
print(b)
(a) 12 (b) 13 (c) 12 (d) 36
33 12 36 21
35
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 121
44. What is the output of below code, when the list L contains [3, 5, 81, 7, 17]?
def test (L):
for i in range (len (L)) :
if(L [i]% 3 = = 0) :
L [i] = L [i] + 4
print(L)
(a) [3, 9, 81, 11, 21] (b) [5, 5, 31, 7, 17]
(c) [7, 5, 85, 7, 17] (d) [7, 9, 85, 11, 21]
(c) 2 # 5 # 9 # (d) 2 # 3 # 4 #
https://t.me/cbseexamsweb
122 CBSE Sample Paper Computer Science Class XII (Term I)
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
Here is a program to check whether a passed string is palindrome or not.
def isPalindrome ( ) :
str1 = input(“Enter string”)
SAMPLE PAPER 7
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 123
54. Identify the statement for blank space in line marked as Statement 5.
(a) left_pos + = 1 (b) left_pos− =1
(c) right_pos− = 1 (d) right_pos+ =1
55. Identify the suitable value for blank space in line marked as Statement 6.
(a) False (b) True
(c) Flag (d) None
SAMPLE PAPER 7
https://t.me/cbseexamsweb
OMR SHEET SP 7
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 125
Answers
1. (a) 2. (d) 3. (c) 4. (b) 5. (b) 6. (a) 7. (c) 8. (d) 9. (b) 10. (b)
11. (c) 12. (b) 13. (a) 14. (c) 15. (a) 16. (c) 17. (b) 18. (c) 19. (b) 20. (d)
21. (b) 22. (d) 23. (b) 24. (c) 25. (b) 26. (a) 27. (a) 28. (d) 29. (b) 30. (b)
31. (d) 32. (b) 33. (a) 34. (b) 35. (d) 36. (c) 37. (a) 38. (c) 39. (d) 40. (a)
41. (b) 42. (a) 43. (c) 44. (c) 45. (d) 46. (b) 47. (a) 48. (b) 49. (a) 50. (c)
51. (a) 52. (b) 53. (b) 54. (d) 55. (b)
SOLUTIONS
1. lambda is a keyword which cannot be used as 11. Built-in functions are known as library
an identifier. functions. These are pre-defined functions
2. A sequence of characters is called string. Strings that are always available for use.
are enclosed by double or single quotes. e.g. type (), input (), etc.
3. Lists provide slice steps which used to extract 12. sys.stdout stands for standard output. To
elements from the list that are not consecutive. write a line for output, you must be call
Value of index number 3 is 6 and after gap of sys.stdout. write().
two elements index number will be 5 whose 13. remove ( ) method is used to remove the
value is 7. existing file. This method does not return any
4. An absolute path is a path that contains the value.
entire path to the file or directory that you need 14. Positional arguments are arguments that need
to access. to be included in the proper position or order.
5. read (size) method specifies how many 15. The method seek() sets the file’s current
characters the string returns. position at the offset.
6. seek() method can be used to change the Syntax
current position in a file. FileObject.seek(offset[,mode])
Syntax Fileobject.seek(offset [,mode]) 16. The total size of the program remains the
where, offset argument indicates the number of same regardless of whether modules are used
bytes to be moved. or not. Modules simply divide the program.
7. ab mode opens a file for appending in binary 17. The function max() is being used to find the
format. The file pointer is at the end of the file if maximum value from among − 13, − 14 and
the file exists. If file does not exist, it creates a False. Since, False amounts to the value zero,
new file for writing. hence we are left with min(0, 12, 17). Hence,
the output is 0 (False).
8. A sequence is an ordered collection of items,
where each time is indexed by an integer. Three 18. Keyword arguments (or named arguments)
types of sequence data types are string, list and are values, when passed into a function, are
tuple. identifiable by specific parameter names.
Keyword arguments specified two stars
9. for loop is used for fixed number of iterations in
followed by a valid identifier in the function
SAMPLE PAPER 7
https://t.me/cbseexamsweb
126 CBSE Sample Paper Computer Science Class XII (Term I)
29. while () statement will start from 3 and go till 41. This program will find all such numbers which
14. It increments 2 in value of ‘a’. So, correct are divisible by 5 but are not a multiple of 7
output is 3 5 7 9 11 13. between 10 to 35 (both included).
30. insert ( ) method is used to insert an element at 42. When test ( ) called then ‘a’ will become 8 and
specified position in the list. b will become 3.
a = 8 + 3 = 11
Syntax list_name.insert(index,element)
b =3+2 = 5
Here, first insert statement adds 14 at index
So, output is 11 5.
number 4 and second insert statement adds 23
at index number 2. 43. It will pass the value of x, y and z and use
these values in statement (x > = y and x < = z)
So, new list will be [2, 3, 23, 9, 12, 14, 4] index
which gives False.
number − 4 represents the 4th element from
last, i.e. 9 44. It will add 4 to those elements which are
completely divided by 3.
31. A function test () displays the elements in
reverse order that each displayed element is 45. The function test() read the file ‘‘Data.txt’’ and
the incremented by 2 of the original element of count the number of times ‘‘My’’ occurs in the
list x. file.
32. dump ( ) is used to write objects to a file. 46. The minimum and maximum index number
SAMPLE PAPER 7
Before use the dump ( ) method, you first have are 1 and 5 respectively. Value for L can be 1, 2,
to import the pickle module. 3, 4 and value for U can be 3, 4, 5. So, range for
for loop can be 1 to 5.
33. 10*4 // 2 + 4 − 2 //2 + 4 − 3 + 5 // 8
47. read(n) method specifies how many characters
= 40 // 2 + 4 − 2 //2 + 4 − 3 + 5 // 8 the string should return. It also includes blank
= 20 + 4 − 2 / / 2 + 4 − 3 + 5 / / 8 space.
= 20 + 4 − 1 + 4 − 3 + 5 / / 8
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 127
48. When test (3) called, then a = 3, b = 20 51. −1 is used to fill up the blank in
a=3+1=4 Statement 2.
b = 20 − 1 = 19 52. right _ pos > = left _ pos condition is used
return 4 +19 = 23 with while loop in Statement 3.
When test ( ) called, then default parameter will be 53. When if condition is true, then false will
used. i.e. a = 10, b = 20 be return.
a = 10 + 1 = 11 So, return False is used to fill up in
b = 20 − 1 = 19 Statement 4.
return 11 + 19 = 30 54. right _ pos + = 1 is used for blank space in
49. This program read the string and change its some line marked as Statement 5.
alphabet and print new string. 55. True is the suitable value for blank space
50. 0 is the correct option to fill up the blank in in line makred as Statement 6.
Statement 1 . It assigns 0 to variable left_pos.
SAMPLE PAPER 7
https://t.me/cbseexamsweb
128 CBSE Sample Paper Computer Science Class XII (Term I)
SAMPLE PAPER 8
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
2. Consider the declaration a={‘a’:11,’b’:2}, which of the following represents the data
type of a?
(a) List (b) Tuple (c) Dictionary (d) String
3. Suppose L=[10,19,45,77,10,22,2], what will be the value of L[3:5]?
(a) [77,10] (b) [45,77] (c) [45,77,10] (d) [77,10,22]
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 129
8. Suppose tuple tup1 = (56, 89, 75, 65, 99). What is the output of tup1[−3]?
(a) 65 (b) 89 (c) 75 (d) Error
17. ……………… function converts all lowercase letters into uppercase letters.
(a) lower ( ) (b) upper ( ) (c) isupper ( ) (d) islower ( )
print(dic1[3])
(a) C (b) 3 (c) {‘C’ : 3} (d) Error
19. Which of the following returns a normalised absolutised version of the pathname
path?
(a) getcwd ( ) (b) abspath ( ) (c) abs ( ) (d) abpath ( )
20. Using ……………… argument, you can declare value using name.
(a) default (b) keyword
(c) positional (d) friendly
https://t.me/cbseexamsweb
130 CBSE Sample Paper Computer Science Class XII (Term I)
21. Using which of the following, we can avoid rewriting the same logic/code again and
again in the program?
(a) Functions (b) Class
(c) Object (d) Keyword
23. This defines the mapping data type which is used in Python.
(a) Dictionary (b) List
(c) Tuple (d) String
24. Statements that allow a program to execute a statement depending upon a given
condition are called
(a) compound statements (b) simple statements
(c) conditional statements (d) null statements
Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
a = 0
b = 1
while(i<n):
print(a)
c = a+b
a = b
b = c
i = i+1
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 131
32. Evaluate the following expression and identify the correct answer.
A = 5 + 6//3 + 10*3//4 + 2 + 3//4
SAMPLE PAPER 8
https://t.me/cbseexamsweb
132 CBSE Sample Paper Computer Science Class XII (Term I)
(a) 81 (b) 81
256 81
(c) 256 (d) 256
81 256
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 133
(a) 65 (b) 65
5 65
(c) 5 (d) 5
65 5
print(i)
(a) 3 (b) 1 (c) 0 (d) Error
https://t.me/cbseexamsweb
134 CBSE Sample Paper Computer Science Class XII (Term I)
(c) 1 (d) 0
2 1
3 2
4 3
4
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 135
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
Rohan wrote a below program in which some code is missing. Answer the below
questions for successfully run that program.
string = input (“Please enter your string:”)
_____ =“ ” # Statement 1
for i in ______ : # Statement 2
str1 = ______ + str1 # Statement 3
print(“String in reverse order :”, ______ ) # Statement 4
if ( ______ ) : # Statement 5
print (“This is a palindrome string.”)
______ # Statement 6
print (“This is not a palindrome string.”)
50. Choose the correct option to fill up the blank in line marked as Statement 1.
(a) str (b) str1 (c) i (d) a
51. Choose the correct option to fill up the blank in line marked as Statement 2.
(a) string (b) str1 (c) str (d) string+1
53. Choose the correct option to fill up the blank in line marked as Statement 4.
(a) string (b) str (c) str1 (d) string +1
54. Choose the correct condition to be used to check palindrome the strings.
(a) string ! = str1 (b) string > = str1 (c) string < = str1 (d) string = = str1
55. Choose the correct option to fill up the blank in line marked as Statement 6.
(a) elif (b) elif : (c) else (d) else :
https://t.me/cbseexamsweb
OMR SHEET SP 8
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 137
Answers
1. (b) 2. (c) 3. (a) 4. (b) 5. (a) 6. (a) 7. (b) 8. (c) 9. (d) 10. (b)
11. (d) 12. (a) 13. (a) 14. (a) 15. (c) 16. (a) 17. (b) 18. (d) 19. (b) 20. (b)
21. (a) 22. (d) 23. (a) 24. (c) 25. (d) 26. (b) 27. (a) 28. (c) 29. (b) 30. (c)
31. (d) 32. (a) 33. (a) 34. (b) 35. (c) 36. (a) 37. (a) 38. (a) 39. (a) 40. (d)
41. (b) 42. (c) 43. (b) 44. (c) 45. (b) 46. (b) 47. (a) 48. (a) 49. (b) 50. (b)
51. (a) 52. (c) 53. (c) 54. (d) 55. (d).
SOLUTIONS
1. S-num is an invalid name for identifier 10. Elements of tuple are immutable that means they
because (-) symbol is not allowed in the cannot be change after creation.
identifier name. 11. Updation in elements of tuple is not possible
2. Python dictionary is used to store the data because it is immutable which cannot be change
in a key:value pair format. The dictionary is after creation.
the data type in Python, which can simulate 12. len( ) is used to calculate the total length of list.
the real-life data arrangement where some 13. r + opens a file for both reading and writing. The
specific value exists for some particular key. file pointer placed at the beginning of the file.
3. To access a range of items in a list, you need 14. A complex number is a number expressed in the
to use slice into a list. One way to do this is to form a + ib, where a (real part) and b (imaginary
use the simple slicing operator (:). If L is a part) are real numbers and i is the imaginary value.
list, the expression L [ start : stop] returns the
portion of the list from index start to index 15. List is a mutable data type that can be changed
stop. after creation.
From given list value of index number 3 16. sys.stdin stands for standard input. To read a line
is 77. from a user, you must be call
sys.stdin. readline ( ).
So, value of L [3:5] is [77, 10].
17. upper ( ) is a string function. This function
4. To open a file, the correct syntax is
converts all lowercase letters into uppercase
FileObject = open (filename [,acce_mode]) letters. It returns the string.
e.g. f = open (“d:\\ para.txt”, “r”)
18. The given code will contain an error. Because 3 is
where f is fileobject, d:\\para.txt is a not a key. A, B, C are keys of dictionary dic1.
filename and r is a access mode.
Values can be accessed only by keys.
5. * is a replication operator that can repeat the
elements of the list. 19. abspath ( ) method returns a normalised
absolutised version of the pathname path that
e.g. L = [1, 2, 3] means returns the complete path name of the
print (L * 2) data file.
Output [1, 2, 3, 1, 2, 3] 20. Using keyword argument, you can declare value
6. The index number should be an integer. using name. Python provides a way of writing
Index of 0 refers to first element, 1 refers to function call where you can write any argument
second element and so on. in any order, but value should be in right form.
SAMPLE PAPER 8
7. LEGB stands for Local Enclosed Global 21. Using functions, we can avoid rewriting the same
Built-in. logic/code again and again in the program. It is
8. −1 represents the last index in the tuple, −2 basically named unit of group of proper
represents the second last element and so statements.
on. So, the output for tuple tup1 [−3] is 75. 22. When a formal set of rules defined for writing a
9. Since print statement gives str1, str1 is program in a particular language, is not followed
written inside double quotes that will be then error raised is known as syntax error.
considered as string. Division by zero is a run-time error not a syntax
error.
https://t.me/cbseexamsweb
138 CBSE Sample Paper Computer Science Class XII (Term I)
23. Mapping is an unordered data type in Python. Iteration 4 while (4 < 5) : true
In Python, there is only one standard mapping print 2
data type called dictionary. c = 2 + 3 = 5
24. A selection statement is a control statement a = 3
that allows statement choosing two or more b = 5
execution paths in a program. These
i = 4 + 1 = 5
statements allow a program to execute a
statement or a set of statements depending Iteration 5 while (5 < 5) : false
upon a given condition. So, ouput is 0
These statements are also called conditional 1
statements or decision statements.
1
25. This program code does not produce any
output because there is no element by defining 2
the range with for loop. 28. In given code, we take two variables-one is
26. Iteration 1 while (4 > 0) : true integer and second is float. Further, we take
another variable which will store the sum of
sum = 0 + 4 = 4
these two variables.
x = 4 − 1 = 3
We can see that the data type of sum variable
Iteration 2 while (3 > 0) : true has been automatically converted into float
sum = 4 + 3 = 7 data type by the Python compiler.
x = 3 − 1 = 2 Syntax to represent the datatype is
Iteration 3 while (2 > 0) : true <class ‘datatype’>
sum = 7 + 2 = 9 29. When myFunc ( ) is called, then the value for
x = 2 − 1 = 1 parameters x and y becomes 25 and 8,
respectively.
Iteration 4 while (1 > 0) : true
So, a = 25 * 2 + 8 − 3
sum = 9 + 1 = 10
= 50 + 8 − 3
x = 1 − 1 = 0
= 50 + 5 = 55
Iteration 5 while (0 > 0) : false
30. ‘story.txt’ is a text file on which we need to
So, output is 10
write data ‘‘Study’’. Python provides write ( )
27. Iteration 1 while (1 < 5) : true method that takes a string entered by user and
print 0 writes it into the file.
c = 0 + 1 = 1 31. List is a mutable type of object which can be
a = 1 changed after creation. There is list [23, 12, 45,
b = 1 72] but also mentioned the value of index
i = 1 + 1 = 2 number 2 as 45.
Value of index number 2 is already 45, so it
Iteration 2 while (2 < 5) : true will not be replaced.
print 1
32. A = 5 + 6//3 + 10*3//4 + 2 + 3//4
c = 1 + 1 = 2
= 5 + 2 + 10 *3//4 + 2 + 3//4
a = 1
b = 2 = 5 + 2 + 30 //4 + 2 + 3 //4
= 5 + 2 + 7 + 2 + 3//4
SAMPLE PAPER 8
i = 2 + 1 = 3
Iteration 3 while (3 < 5) : true = 5+ 2+ 7+ 2+ 0
print 1 = 7+ 7+ 2+ 0
c = 1 + 2 = 3 = 14 + 2 + 0 = 16
a = 2 33. The arguments in Python functions may have
b = 3 implicit values. An implicit value is used, if no
i = 3 + 1 = 4 value is provided.
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 139
Here we created a power function. The 43. : is a slice operator, which returns the sub-part
function has one argument with an implicit of given any data type as string, list, tuple, etc.
value. We can call the function with one or two Index number is started from 0, so the value of
arguments. index number 2 is ‘Mathematics’ and index
When function f(4) called output, will be 81 number 3 is 44.
and when function f(4, 4) called, output will 44. Variable ‘a’ is incremented by 2 and printed
be 256. thrice.
34. This code opens a file ‘story.txt’ and read the 45. in operator is used to check if a value exists in
file word-for-word and len( ) method is used a sequence or not.
to find the length or number of bytes. There is no element as ‘put’ so it will execute
35. The given code basically finds the sum of the else part and print ‘False’.
values of keys. 46. The loop runs one time and the loop runs an
36. There is no output because “7” is not available extra parenthesis along with a comma is added
in “123456”. to the tuple (as a=(a’)).
37. A new list object is created in the function and When input is ‘Computer’ .
the reference is lost. This can be checked by So, output is ((‘Computer’,),) .
comparing the id of val before and after
val = [5]. 47. for loop prints 0 to 3 and when i becomes 4 it
will terminate the if statement. The else part is
So, output is [4].
executed if control does not break out of the
38. The global statement is used to declare that ‘a’ loop.
is a global variable. Hence, when we assign a
48. In given code, when function runs and it gives
value to ‘a’ inside the function, that change is
the output of a + b and a − b. i.e. 30 and − 10,
reflected when we use the value of ‘a’ in the
respectively. Then, assignment operator is
main block.
used to assign the value of a and b.
When myFunc() is called, it will give output 65
the value of a. 49. The variable count declared outside the
function is global variable and also the count
After function called, print statement prints 5
variable being referenced in the function is the
the value of a which is local variable.
same global variable defined outside of the
So, output is 65 function. So, the changes made to variable in
5 the function is reflected to the original variable.
39. This program updates the elements of list. So, the output of the program is 5.
So, first element of list 23 is replaced by 56. 50. str1 is a variable that stores the empty string.
40. The given code will result in an error because 51. string stores the string that entered by user. It
‘a’ is a global variable. Had it been a local will be the original string.
variable, the output would be 27 52. i will be added to str1.
Arihant 53. str1 stores the reverse order of string.
41. read( ) is used to return a string containing all e.g. if string = ADD, then the value of str1 will
characters in a file. So, the data type of val will be DDA.
be string. 54. A string is said to be palindrome if it reads the
42. In a function, any change made into an same backward as forward.
SAMPLE PAPER 8
immutable data type is not reflected outside 55. In conditional statements, when the condition
the function. of if is false, then statements under else: will be
So, value of i will remain same, i.e. 0. executed.
https://t.me/cbseexamsweb
140 CBSE Sample Paper Computer Science Class XII (Term I)
SAMPLE PAPER 9
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
list1=list()
print(list1)
(a) () (b) (,) (c) [] (d) Error
5. To add a new element to the list, which of the following statement is used?
(a) list1.add(x) (b) list1.addLast(x) (c) list1.append(x) (d) list1.addEnd(x)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 141
9. Which of the following is the mode for both writing and reading in binary format in
file?
(a) wb+ (b) w (c) wb (d) w+
10. Which of the following is false about “import modulename” form of import?
(a) The namespace of imported module becomes part of importing module.
(b) This form of import prevents name clash.
(c) The namespace of imported module becomes available to importing module.
(d) The identifiers in module are accessed as : modulename.identifier.
12. How many keyword arguments can be passed to a function in a single function call?
(a) Zero (b) One (c) Zero or more (d) One or more
13. If return statement is not used inside the function, the function will return
(a) None (b) 0
(c) Null (d) Arbitrary value
14. ……… are the arguments passed to a function in correct positional order.
(a) Required arguments (b) Keyword arguments
(c) Default arguments (d) Variable-length arguments
19. Which of the following is a value passed to the function during the function call?
(a) Argument (b) Parameter (c) Keyword (d) Statement
20. Which of the following is correct code to remove the file “story.txt”?
(a) remove(“story.txt”) (b) remove(story.txt)
(c) os.remove(“story.txt”) (d) os.remove=“story.txt”
https://t.me/cbseexamsweb
142 CBSE Sample Paper Computer Science Class XII (Term I)
24. Which type of statement specifies the order in which actions are executed?
(a) Null statement (b) Control statement
(c) Compound statement (d) Simple statement
Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
print(x+2)
x = 4
x = − 5
Func(37)
(a) 37 (b) 41 (c) 39 (d) 32
28. Evaluate the following expression and identify the correct answer.
A = 5 * 5 + 4 / / 5 + 15 − 9 / / 2 + 10
(a) 36 (b) 46 (c) 47 (d) 56
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 143
https://t.me/cbseexamsweb
144 CBSE Sample Paper Computer Science Class XII (Term I)
import pickle
tup1=(3, 7, 9, 6, 2)
myfile=open (“story.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)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 145
for i in L :
if i in [‘a’, ‘e’, ‘i’, ‘o’, ‘u’]:
X = X + i.swapcase ()
else:
if (count% 2 ! = 0) :
X = X + str (len (L [: count]))
else:
https://t.me/cbseexamsweb
146 CBSE Sample Paper Computer Science Class XII (Term I)
X =X + i
count = count + 1
print (X)
Findoutput ()
(a) eA3N (b) EA3n (c) EA3N (d) Ea3n
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 147
print(j)
myfile.close()
(a) 3 (b) 2 (c) None (d) Error
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
Below is a program to delete the line having word (passed as argument). Answer the
questions that follow to execute the program successfully.
import _____ # Statement 1
def filedel(word) :
file1 = open(“Python.txt ”,“ _____”) # Statement 2
nfile = open(“algo.txt”, “w”)
while True :
line = file1._____ # Statement 3
if not line :
break
else :
if word in line :
SAMPLE PAPER 9
_____ # Statement 4
else :
print(line)
nfile. _____ (line) # Statement 5
file1.close()
_____ . close() # Statement 6
filedel(‘write’)
https://t.me/cbseexamsweb
148 CBSE Sample Paper Computer Science Class XII (Term I)
50. Choose the correct option to fill up the blank in line marked as Statement 1.
(a) csv (b) bin (c) os (d) python
51. In which mode, program should open the file to delete the line in statement 2?
(a) w (b) r
(c) r+ (d) a+
52. Choose the correct option to fill up the blank in line marked as Statement 3.
(a) read() (b) read(n)
(c) readlines() (d) readline()
53. Identify the missing code for blank space in line marked as Statement 4.
(a) True (b) Flag
(c) Pass (d) False
54. Choose the correct option to fill up the blank in line marked as Statement 5.
(a) read (b) write
(c) writelines (d) writeline
55. Choose the correct option to fill up the blank in line marked as Statement 6.
(a) file 1 (b) file
(c) nfile (d) None
SAMPLE PAPER 9
https://t.me/cbseexamsweb
OMR SHEET SP 9
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
150 CBSE Sample Paper Computer Science Class XII (Term I)
Answers
1. (d) 2. (c) 3. (b) 4. (c) 5. (c) 6. (b) 7. (a) 8. (a) 9. (a) 10. (a)
11. (c) 12. (c) 13. (a) 14. (a) 15. (b) 16. (c) 17. (b) 18. (c) 19. (a) 20. (c)
21. (d) 22. (c) 23. (b) 24. (b) 25. (d) 26. (d) 27. (c) 28. (b) 29. (c) 30. (d)
31. (c) 32. (a) 33. (b) 34. (a) 35. (a) 36. (d) 37. (d) 38. (d) 39. (b) 40. (b)
41. (a) 42. (b) 43. (d) 44. (a) 45. (b) 46. (b) 47. (b) 48. (d) 49. (a) 50. (c)
51. (b) 52. (d) 53. (c) 54. (b) 55. (c)
SOLUTIONS
1. Identifiers are used to identify a variable, 13. If return statement is not used inside the
function or other entities in a program. function, the function will return None.
It can be of any length. 14. Required arguments are the arguments passed
2. Bitwise operators work on bits and perform to a function in correct positional order. Here,
bit-by-bit operation. These operators are &, ^ the number of arguments in the function call
and /. should match exactly with the function
definition.
3. Output a=3+2.66 =5.66
15. Num = 2 + 3 − 1 * 3
4. There is no element in () that means it is an
empty list. Empty list is represented by []. =2 +3−3= 5−3=2
5. append(x) is used to add an element to the list 16. range () is used to generate a sequence of
at end. numbers overtime. for statement encloses one
6. round (53.7) does not contain any error, as it or more statements that form a body of the
will round the number which has passed as loop, the statement in the loop repeat
parameter. continuously a certain number of times.
Syntax
7. readlines () method will return a list of
strings,each separated by ‘\n’. for variable in range (start,stop,step) :
17. In packing, we put values together into a new
Syntax fileHandle.readlines()
tuple while in unpacking we extract those
8. The readline () function reads a single line values into a single variable.
from the file fh = open(“filename”, “r”)
18. Strings are also provide slice steps which used
content=fh.readline(). to extract characters from string that are not
9. wb+ opens a file for both writing and reading consecutive.
in binary format. Overwrites the existing file if 19. An argument is a value passed to the function
the file exists. If the file does not exist, creates a during the function call which is received for
new file for reading and writing. corresponding parameter defined in function
10. In the “import modulename” form of import, header.
the namespace of imported module becomes 20. remove() is used to remove the existing file.
available to, but not part of the importing This method does not return any value.
module.
SAMPLE PAPER 9
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 151
23. c = 12 / /10 + 4 * 2 36. The values given during function call is taken
= 1+ 4 *2 into consideration, i.e. i = 5 and j = 4.
=1+8 i=5+4=9
c=9 j=4+1=5
d = 9 − 10 = − 1 So, output is 9 5.
prints− 1 37. Objects of type int are not iterable.
24. Control statement specifies the order in which 38. It will give error because objects of type int are
actions are executed. not iterable.
25. It will give an error because operator cannot 39. dump() is used to write object to a file before
add list with other type object as number or use the dump() method, you have to import
string. pickle module.
26. This code gives TypeError because cannot Syntax pickle. dump(object_to_pickle,
multiply sequence by non-int of type “tuple”. fileobject)
27. The value passed to the function Func() is 37. 40. This program opens a file ‘‘IMP.TXT’’ and read
This value is incremented by 2 and then the content word-for-word. It counts and
printed. display the occurrence of alphabet E and U
28. A = 5* 5 + 4 / / 5 + 15 − 9 / / 2 + 10 (including small cases).
= 25 + 4 / /5 + 15 − 9 / /2 + 10 41. It will read the element of list and print them
= 25 + 0 + 15 − 9 / /2 + 10 with random module.
= 25 + 0 + 15 − 4 + 10 42. It takes string as “earn” and iterate the
= 25 + 15 − 4 + 10 characters of given string. It apply some
= 40 − 4 + 10 condition and print them.
https://t.me/cbseexamsweb
152 CBSE Sample Paper Computer Science Class XII (Term I)
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 153
SAMPLE PAPER 10
COMPUTER SCIENCE
A Highly Simulated Practice Questions Paper
for CBSE Class XII (Term I) Examination
Instructions
1. This question paper is divided into three sections.
2. Section - A contains 25 questions (1-25). Attempt any 20 questions.
3. Section - B contains 24 questions (26-49). Attempt any 20 questions.
4. Section - C contains 6 case study based questions (50-55). Attempt any 5 questions.
5. Each question carries 0.77 mark.
6. There is no negative marking.
Maximum Marks : 35
Roll No. Time allowed : 90 min
Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.
1. In this type conversion, Python automatically converts one data type to another data
type.
(a) Explicit (b) Implicit (c) Both (a) and (b) (d) None
2. Which of the symbol is used for processing in flowchart?
t=“LEARN”
t1=tuple(t)
print(t1)
(a) (L, E, A, R, N) (b) (‘L’, ‘E’, ‘A’, ‘R’, ‘N’)
(c) [‘L’, ‘E’, ‘A’, ‘R’, ‘N’] (d) Error
5. Which of the following is also called iterate over a tuple?
(a) Slicing (b) Accessing (c) Replicating (d) Traversing
https://t.me/cbseexamsweb
154 CBSE Sample Paper Computer Science Class XII (Term I)
x = 2
Total (3, x)
In given code, a, b denotes the
(a) arguments (b) parameters
(c) functions (d) values
16. What data type is the object L?
L = [23, ‘Computer’, 12.5, 56, 8]
(a) list (b) dictionary
(c) array (d) tuple
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 155
Section B
SAMPLE PAPER 10
https://t.me/cbseexamsweb
156 CBSE Sample Paper Computer Science Class XII (Term I)
(a) 1 (b) 0
2 1
3 2
4 3
(c) 0 (d) Error
1
2
3
4
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 157
print(d)
(a) ((1, 2, 3) : 0, (2, 10, 4) : 8) (b) [(1, 2, 3) : 0, (2, 10, 4) : 8)]
(c) {(1, 2, 3) : 0, (2, 10, 4) : 8} (d) Error
37. What is the output of following code?
list1=[ ]
for i in range (10, 30):
if (i%3 = = 0) and (i%2!=0) :
list1.append (str(i))
print(‘,’. join(list1))
https://t.me/cbseexamsweb
158 CBSE Sample Paper Computer Science Class XII (Term I)
3 4 7 9 2 4 5
What is the output of following code?
def myFun(val):
for i in range (len(val) − 1 , − 1 , − 1):
print(val[i]*4)
(a) [3, 4, 7, 9, 2, 4, 5] (b) [5, 4, 2, 9, 7, 4, 3]
(c) [5, 16, 8, 9, 7, 16, 3] (d) [20, 16, 8, 36, 28, 16, 12]
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 159
https://t.me/cbseexamsweb
160 CBSE Sample Paper Computer Science Class XII (Term I)
Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.
Below is a program to display all the records in a file along with line/record number
from file “status.txt”. Answer the questions that follow to execute the program
successfully.
f= open (_____ , “r”) #Line 1
count= 0
rec=“ ”
while _____ : #Line 2
rec = f . _____ #Line 3
if rec = = “ ”:
_____ #Line 4
count = _____ #Line 5
print(count, rec, end = “ ”)
_____ #Line 6
50. Choose the correct option to fill up the blank marked as Line 1.
(a) status (b) “status.txt” (c) status.txt (d) file.txt
51. Choose the correct option to fill up the blank marked as Line 2.
(a) 0 (b) 1 (c) False (d) True
SAMPLE PAPER 10
52. Which function will be used to read the content of file marked as Line 3?
(a) readline() (b) readlines() (c) read() (d) read(n)
53. Choose the correct option to fill up the blank marked as Line 4.
(a) continue (b) break (c) goto (d) label
54. Which value will be assign to variable count in Line 5?
(a) count −1 (b) count*i (c) count + 1 (d) count + i
55. Identify the missing code in Line 6.
(a) f.close (b) myfile.close (c) file.close() (d) f.close()
https://t.me/cbseexamsweb
OMR SHEET SP 10
Roll No.
Instructions
Use black or blue ball point pens and avoid Gel & Fountain pens for filling the OMR sheet.
Darken the bubbles completely. Don’t put a tick mark or a cross mark, half-filled or over-filled bubbles will not be read
by the software.
✔ ✗
Correct Incorrect Incorrect Incorrect
Do not write anything on the OMR Sheet.
Multiple markings are invalid.
1 20 38
2 21 39
3 22 40
4 23 41
5 24 42
6 25 43
7 26 44
8 27 45
9 28 46
10 29 47
11 30 48
12 31 49
13 32 50
14 33 51
15 34 52
16 35 53
17 36 54
18 37 55
19
https://t.me/cbseexamsweb
162 CBSE Sample Paper Computer Science Class XII (Term I)
Answers
1. (b) 2. (c) 3. (c) 4. (b) 5. (d) 6. (a) 7. (d) 8. (c) 9. (d) 10. (b)
11. (a) 12. (b) 13. (b) 14. (d) 15. (b) 16. (a) 17. (c) 18. (c) 19. (b) 20. (d)
21. (a) 22. (c) 23. (b) 24. (b) 25. (a) 26. (a) 27. (d) 28. (a) 29. (c) 30. (a)
31. (b) 32. (a) 33. (b) 34. (d) 35. (a) 36. (c) 37. (c) 38. (b) 39. (d) 40. (d)
41. (a) 42. (d) 43. (a) 44. (c) 45. (c) 46. (a) 47. (b) 48. (a) 49. (b) 50. (b)
51. (d) 52. (a) 53. (b) 54. (c) 55. (d)
SOLUTIONS
1. In implicit type conversion, Python 11. A local variable can be accessed only by the
automatically converts one data type to statements of that functions, in which these are
another data type. This process does not need declared. The local variables are also called as
user involvement. the internal variables.
2. A flowchart is a graphical representation of the 12. The output of code is a list containing only
steps taken to reach a certain result. keys of the dictionary dic1.
For processing, box is used. 13. a=int(53.46+3/3)
3. import is a keyword, which cannot be used as =int(53.46+1)
identifier name. =int(54.46)=54
Special character (such as Sum^2) and space So, output is 54.
(such as Sum Func) cannot be used as 14. The standard file streams are simply
identifier So, valid identifer is Num123. pre-opened Python file objects that are
4. tuple() is used to convert string and list into automatically connected to the program’s
tuple. standard streams when Python starts up.
There are three file streams used in Python’s
5. Traversing a tuple is a technique to access an
file handling as sys.stdin, sys.stdout and
individual element of that tuple. It is also
sys.stderr.
called iterate over a tuple.
15. A parameter is a variable used to define a
6. index() returns the index of first occurrence of
particular value during a function definition.
element in the tuple.
So, a and b are parameters.
7. flush() will force out any unsaved data that
exists in a program buffer to the actual file. 16. In Python programming, a list is created by
Typically, data will be copied from the placing all the items (elements) inside square
program buffer to the operating system buffer brackets [], separated by commas (,).
(file). 17. // is the operator for truncation division. It is
8. ab+ opens a file both appending and reading in called, so because it returns only the integer
binary format. The file pointer is at the end of part of the quotient, truncating the decimal
the file, if the file exists. part. For example, 20//3 = 6.
18. If a local variable exists with the same name as
SAMPLE PAPER 10
https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 163
20. readlines() is used to read all the lines at a 31. The value of min could be 1, 2, 3 and the value
single go and then return them as each line a of max could be 2, 3, 4.
string element in a list. This function can be So, range for ‘for’ loop will be 1 to 5, in which
used for small files, as it reads the whole file elements of lists are 2, 3, 4, 5 and 6.
content to the memory, then split it into
32. Iteration 1 while (1 < 10) : true
separate lines.
prints 1
21. The functions pickle. loads (), pickle.dump () i = 1 + 3 = 4
and pickle.load () accept only one argument.
Iteration 2 while (4 < 10) : true
The function pickle.dumps () can accept more
prints 4
than one argument.
i = 4 + 3 = 7
22. In function declaration, it must to give the Iteration 3 while (7 < 10) : true
return statement. return val will return the
prints 7
value of variable ‘val’.
i = 7+ 3 = 10
23. Relative path does not start with a leading Iteration 4 while (10 < 10) : false
forward slash and is interpreted from the
The else part is executed when the condition in
perspective of the current working directory.
the while statement is false.
24. In a program, a run-time error is an error that prints 2
occurs while program is running after being So, output is 1
successfully compiled. 4
Trying to access a file is an example of 7
run-time error.
2
25. An exception can be defined as an abnormal
33. We can loop over a generator object only once.
condition in a program resulting in the
disruption to the flow of the program. for loop starts form 1 to 4 and prints iterable
Whenever an exception occurs, the program number i.e. 1
halts the execution and thus the further code is 2
not executed. 3
26. The break statement alters the normal flow of 4
execution as it terminates the current loop and 5
resumes execution of the statement following 34. SyntaxError, not in is not allowed in for loop.
that loop.
35. A = 10 * 5 + 3 / / 4 + 12 − 8 / /3 + 2 − 1
loop starts from 1 to 10, but when i becomes 5
it terminates the loop. So, output is 1 = 50 + 3 / /4 + 12 − 8 / /3 + 2 − 1
2 = 50 + 0 + 12 − 8 / /3 + 2 − 1
3 = 50 + 0 + 12 − 2 + 2 − 1
4 = 62 − 2 + 2 − 1
27. The program segment does not produce any = 60 + 2 − 1
output, because there will not be any element
= 62 − 1
in given range.
= 61
28. del keyword is used to delete the key that is
present in the dictionary. 36. It defines the dictionary d in which (1, 2, 3) and
(2, 10, 4) are keys and 0 and 8 are values with
SAMPLE PAPER 10
https://t.me/cbseexamsweb
164 CBSE Sample Paper Computer Science Class XII (Term I)
then variable add stores the sum of values of characters from file with blank space and print
dictionary, i.e. 4 + 14 = 18 them.
39. any() returns True if atleast one element is 48. It opens a file ‘learn.txt’ in read mode and read
present in the tuple, otherwise returns False. the character from file and find the length of
40. When a function takes a string as an argument file with len() method in bytes.
it prints that string as same pattern. 49. list1 is a nested list in which sub-list is at index
41. test () function takes two parameters. When number 2.
test () calls with one parameter, then it will So, the list1[2] [0] is the index number of first
take default value of n, i.e. 1. When test () calls element of sub-list which will be replaced by
with two parameters, then it will take own 5.4.
value of n, i.e. 2. So, new list is [2, 3, [5.4, 5], 4].
42. Function myFun(val) displays the element in 50. ‘‘status.txt’’ is the correct option to fill up the
reverse order such that each displayed element is blank marked as Line 1. It is a text file that
four times of the original element of the list val. contains some content.
43. In given code, the statement succeeding the 51. True is the correct option to fill up the blank
statement global val informs Python to marked as Line 2. It satisfies the while
increment the global variable val. condition.
Hence, the output is 10. i.e. 7+3, which is also 52. readline() method will read from a file
the value for global val. When val is reassigned line-by-line. For readline(), a line is terminated
with the value 2 the local val hides the global by ‘\n’ or End of Line (EOL) (i.e. new line
val and hence val is printed. character).
44. It will print the value of n is 45 both times 53. break statement alters the normal flow of
because both print statements under function execution as it terminates the current loop and
myFunc1(). resumes execution of the statement following
45. Func(list1) accepts the list list1 as an argument that loop. This code break the flow of
and convert those elements to multiply by 5 execution when if condition becomes true.
which are not divisible by 3. 54. count+1 is the correct option to assign to
46. read(n) method specifies how many characters variable count. It will increase the value of
the string should return. count by 1.
Syntax <Filehandle>.read(n) 55. f.close() is used to close the file ‘‘status.txt’’.
47. It opens a file ‘‘exam.txt’’ in read mode and It is important to close files as soon as you
read first 10 characters from file with blank have finished your work with file. Opened file
space and print them. After read second 15 is closed by calling the close() method of its file
object.
SAMPLE PAPER 10
https://t.me/cbseexamsweb