0% found this document useful (0 votes)
8K views

Arihant Computer Science Class 12 Term 1 Sample Papers

This document provides a one day revision of key concepts for the Computer Science exam, including: 1. An overview of Python including its design, character set, tokens like identifiers and keywords, and operators like unary, binary, and punctuators. 2. Definitions of expressions as combinations of operators, constants, and variables that evaluate to a value, and statements as logical instructions that Python can execute. 3. A brief tour of Python concepts to review in one day including data types, operators, control flow, functions, files, and classes. Practicing sample questions is also recommended for exam preparation.

Uploaded by

Yageb Aggin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8K views

Arihant Computer Science Class 12 Term 1 Sample Papers

This document provides a one day revision of key concepts for the Computer Science exam, including: 1. An overview of Python including its design, character set, tokens like identifiers and keywords, and operators like unary, binary, and punctuators. 2. Definitions of expressions as combinations of operators, constants, and variables that evaluate to a value, and statements as logical instructions that Python can execute. 3. A brief tour of Python concepts to review in one day including data types, operators, control flow, functions, files, and classes. Practicing sample questions is also recommended for exam preparation.

Uploaded by

Yageb Aggin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 171

https://t.

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

ARIHANT PRAKASHAN (School Division Series)

https://t.me/cbseexamsweb
ARIHANT PRAKASHAN (School Division Series)
All Rights Reserved

© Publisher

Administrative & Production Offices


Regd. Office
‘Ramchhaya’ 4577/15, Agarwal Road, Darya Ganj, New Delhi -110002
Tele: 011- 47630600, 43518550

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

Sample Paper 1 43-54

Sample Paper 2 55-67

Sample Paper 3 68-80

Sample Paper 4 81-91

Sample Paper 5 92-102

Sample Paper 6 103-114

Sample Paper 7 115-127

Sample Paper 8 128-139

Sample Paper 9 140-152

Sample Paper 10 153-164

Watch Free Learning Videos

Video Solutions of CBSE Sample Papers


Chapterwise Important MCQs
CBSE Case Based MCQs
CBSE Updates

Much more valuable content will be available regularly

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 -

II. Computer Networks ---

III. Database Management


Total

Unit No. Unit Name Term I Term II

I. Computational Thinking and Programming -

II. Computer Networks ---

III. Database Management ---


Total

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

Focus on Theory Learn to Identify Wrong Answers


MCQs can be formed from any part or The simplest trick is, observe the options
line of the chapter. So, strong command first and take out the least possible one
on theory will increase your chances to and repeat the process until you reach
solve objective questions correctly and the correct option.
quickly.
Analyze your Performance
Practice of Solving MCQs During the practice of MCQs you can
Cracking an MCQ-based examination identify your weak & strong
requires you to be familiar with the topics/chapter by analyzing incorrect
question format, so continuous practice answers, in this way you will get an
will make you more efficient in solving awareness about your weaker topics.
MCQs.
Practice through Sample Papers
Speed & Accuracy Solving more & more papers will make
In MCQ-based examination, you need you more efficient and smarter for
both speed and accuracy, if your exams. Solve lots of Sample Papers
accuracy is good but speed is slow then given in a good Sample Papers book.
you might attempt less questions
resulting in low score.

Attempting MCQs in Exams

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

● Python Revision Tour-I


1. Python It is a general purpose interpreted, values. The values that the operators work on are
interactive, object oriented and high level called operands.
programming language. It was initially designed by Python supports two types of operators as follows
Guido Van Rossum in 1991 and developed by ● Unary operators
Python Software Foundation.
● Binary operators
2. Python Character Set Character set is a set of
valid characters that represents any digit, alphabet (v) Punctuators A punctuator is a token that has
and special symbol. The character used in a syntactic and semantic meaning to the compiler,
Python source program belongs to unicode but the exact significance depends on the
standard. context. Punctuators (separators) are used to
separate line of codes, variables etc.
3. Python Tokens A smallest individual unit in a
program is known as token or lexical unit or lexical 4. Expression is a combination of operators,
element. constants and variables. Any part in a program
which can have a value, is an expression. It will
The Python has following tokens: have operands and operators together to produce
(i) Identifiers Identifiers are names used to identify a value.
a variable, function, or other entities in a 5. Statement in Python is a logical instruction which
program. Python interpreter can read and execute. It could
(ii) Keywords Keywords are predefined reserved be an expression or assignment statement.
words that have some special or predefined 6. Comments are used to add a remark or a note in
meanings. These are reserved for special the source code that are ignored by the interpreter
purpose and must not be used as identifier or compiler and are not executed by the computer.
names.
7. A function is a self contained block of statements
(iii) Constants or Literals Literals refer to fixed which are kept together to perform a specific task
values that the program may not alter (change) in related manner.
ONE DAY REVISION

during the program execution.


8. Blocks and indentation indicate the relationship
Python allows several types of literals as follows between various statements and thus allow us to get
(a) Numeric literals a better picture of the overall organisation and
(b) String literals structure of the solution given in the program. It
improves the readability of the program.
(c) Boolean literals
9. Variables In a program, a variable is uniquely
(d) Special literal None
identified by a name (identifier). Variable refers to
(e) Literal collections an object - an item or element that is stored in the
(iv) Operators An operator is used to perform memory. Value of a variable can be a string,
specific mathematical or logical operation on numeric or any combination of alphanumeric
characters.

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

● Python Revision Tour-II


1. Strings A sequence of characters is called string. (i) Accessing Values in Strings Each individual
Strings are used by programming languages to character in a string can be assessed using a
manipulate text such as words and sentences. technique called indexing. The index specifies
Strings literal in Python are enclosed by double the character to be accessed in the string and is
quotes or single quotes. String literals can be span written in square brackets [].
multiple lines, to write these strings triple quotes (ii) String Slicing To access some part of a string or
‘‘‘ ’’’ are used. substring, we use a method called slicing.

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 03

This can be done by specifying an index range.


Slice operation is performed on string with the use 2. Lists In Python, list is an ordered sequence, which
of colon (:). string_name [start : stop] is used to store multiple data at the same time.
List contains a sequence of heterogeneous
(iii) Traversing a String Traversing is a technique to elements which store integer, string as well as
iterate the character of string, one character at a object.
time. It just means to process every character in a
In Python, lists can be created to put the elements
string, usually from left end to right end.
separated by the comma ( ,) in square brackets [ ].
(iv) String Operators
(i) Accessing Lists To access the list’s elements,
(a) Basic Operators index number is used. Use the index operator
● String Concatenation Operator (+) String
[ ] to access the elements of a list. The index
concatenation is the technique of should be an integer. Index 0 refers to first
combining two strings. The ‘+’ operator is element, 1 refers to second element and so on.
used for string concatenation. While the index of -1 refers to the last element,
● String Replication Operator ( ) Python
* -2 refers to the second last element and so on.
allows us to repeat the given string using
(ii) Traversing a List Traversing a list is a
repetition operator which is denoted by
technique to access an individual element of
symbol (*). Asterisk sign (*) when used
with numeric data type it performs that list. It is also called iterate over a list.
multiplication operation, but when this sign 3. Tuples A tuple is an ordered sequence of
is used with one string and one number, it elements of different data types, such as integer,
performs string replication operation. float, string, list or even a tuple. Tuple holds a
(b) Comparison Operators These operators are sequence of heterogeneous elements, it stores a
also called relational operators in Python fixed set of elements and do not allow changes.
that compare the values of two string ● To create a tuple in Python, put all the elements

operands and return True or False based on in a parentheses ( ), separated by commas. We


whether the condition is met. can have tuple of same type of data items as
Python string comparison can be performed well as mixed type of data items.
using comparison operators (= =, >, <, !=, < ● A tuple can contain sub-tuple which in turn can

=, >=). contain sub-tuples themselves and so on. This


is known as nested tuple.
(c) Membership Operators These operators are
● Packing and Unpacking Tuples In Python,
used to validate the membership of a value in
a string. These operators are used to find out tuples are collection of elements which are
whether a value is a member of a string or separated by commas. It packs elements or
value together so, this is called packing. In
not.
other way, it is called unpacking of a tuple of
There are two membership operators for values into a variable. In packing, we put values
strings in Python as follows together into a new tuple while in unpacking we
● in Operator This operator is used to check extract those values into a single variable.
if a value exists in a sequence or not. It 4. Dictionary In Python, dictionary is an unordered
evaluates True if it finds a variable in the collection of data values that store the key : value
specified sequence and False otherwise. pair instead of single value as an element. Keys of
● not in Operator This operator is the
a dictionary must be unique and of immutable
opposite of ‘in’ operator. So, if a value does data types such as strings, tuples etc.
not exist in the sequence, then it will return ● To create a dictionary in Python, key : value pair
a True else it will return a False.
is used. Dictionary is list in curly brackets,
(d) Identity Operator In Python, identity inside these curly brackets, keys and values are
ONE DAY REVISION

operators are used to determine whether a declared.


value is of a certain class or type. 5. Debugging Programs The process of identifying
There are two types of identity operators as and removing such mistakes (also known as bugs
● is Operator This operator returns True if or errors) from a program is called debugging.
both the operands point to same memory (i) Error An error is a flaw, fault or failure in a
location. computer program that causes it to produce an
● is not Operator This operator returns True
incorrect or unexpected result or to behave in
if both the operands point to different unintended ways.
memory location.

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

the third positional argument listed third etc.


def keyword is followed by the function name and
parentheses (). 7. Returning Values from Functions
● Functions Returning Some Value (Non-void
Any input parameters or arguments should be
Functions) This function is used to create a
placed within these parentheses.
specific task. After completion that task it returns
There is a colon (:) at the end of def line. some result in term of value. Non-void functions
4. Calling a Function Function definition part only are also known as fruitful functions. Non-void
define the name of function and specify the function can return value in various form.
parameters. Syntax return < value>

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

● write() This method takes a string and writes it


before closing any file.
into the file. This method does not add a Syntax FileObject.flush()
newline character (‘\n’) to the end of the string. (vi) Random Access Methods Python provides two
Syntax <FileHandle>.write(str1) methods to perform random access operations in
● writelines () Whenever, we have to write a a file. These methods help you to manipulate the
sequence of string to a file, we will use position of file pointer and thus you can read and
writelines() instead of write(). write from desired position in the file.
● tell() Method This method tells you the current
Syntax <FileHandle>.writelines(L)
position within the file, measured in bytes from
(iv) Reading from Files After writing information the beginning of the file.
into a file, you must need to read that data at Syntax File0bject.tell()

https://t.me/cbseexamsweb
06 CBSE Sample Paper Computer Science Class XII (Term I)

● seek() Method This method can be used to import pickle


change the current position in a file. This ......
method does not return any value. ......
Syntax File0bject.seek(offset[,mode]) ......
3. Binary File It is a file that contains information in object=pickle.load(File0bject)
the same format as it is held in memory. In binary 4. CSV File CSV (Comma Separated Values) format
files, no delimiters are used for a line and no is one of the most simple and common ways to
translations occur here. They represent the actual store data in tabular form. Each record consists of
content such as image, audio, video, executable one or more fields separated by commas. To
files, etc. These files are not human readable. The represent a CSV file, it must be saved with the .csv
file extension of binary file is .dat. file extension.
(i) Working with Binary File Python object handles (i) Working with csv file csv files are used to store
the binary files. Python provides a special a large number of variables or data. They are
module-the pickle module which can be used to incredibly simplified spreadsheets. Each line in a
store any kind of object in file. csv file is a data record.
(ii) Using dump( ) Method This method is used to (ii) Read from CSV File Using csv.reader() To
write objects to a file. Before use the dump( ) read data from csv files, you must use the
method, you first have to import the pickle reader() function to generate a reader object.
module. This function returns a reader object which is an
Syntax iterator of lines in the csv file.
import pickle Syntax csv.reader(<FileHandle>)
......
(iii) Write into a CSV File Using csv.writerow() To
......
write an existing file, you must first open the file
......
in one of writing modes (w, a or r+) first. For this,
pickle.dump(object_to_pickle,File0bject)
writerow() function is used in Python for csv files.
(iii) Using load() Method
This function writes items in a sequence (list,
This method is used to load data from a binary tuple or string) separating them by comma
file. character.
Syntax
ONE DAY REVISION

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

1. Python Revision Tour-I


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 of the following is not a valid identifier?
(a) _Num (b) Sum123 (c) num^2 (d) name_1

2. Which of the following is a keyword that has pre-defined meaning?


(a) python (b) data type
(c) global (d) variable

3. What is the output of following code?


i=2
while (i<10):
if(i==6):
break
print(i)
i=i+2
(a) 2 (b) 2
4 3
4
(c) 2 (d) 2
3 4
4 6
6
THE QUALIFIERS

4. Which statement is used for the condition a loop is to be repeated 30 times?


(a) for i in range (0, 30) : (b) for i in range (0, 30, +1):
(c) for i in range (1, 31, 1): (d) All of these

5. What is the output of following code?


mul=3
value=10
for i in range (1, 6, 2):

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

6. Evaluate the expression and identify the correct answer.


A = 5 * 3 / /4 + 6 / /8 + 7 − 3 + 9 / /3 + 7
(a) 17 (b) 20
(c) 27 (d) 14

7. What is the output of following code?


n=4
f=1
while (n>0):
f=f*n
n=n−1
print(f)
(a) 24 (b) 120
(c) 10 (d) Error

8. What is the output of following code?


n = 156
f = 0
x = 0
while (n > 3) :
r = n% 100
if (r % 2 ! = 0):
f + = r
else :
x + = r
n/=100
print(f − x)
(a) 56 (b) − 56
(c) 55 (d) 155

9. Identify the output of following code.


THE QUALIFIERS

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

10. Identify the output of following code.


for i in range (− 7, − 20, − 2):
print (i+2)
(a) −7 (b) − 20
−9 − 18
− 11 − 16
− 13 − 14
− 15 − 12
− 17 − 10
−8

(c) None (d) Error

11. What is the output of following code?


x=1
for i in range (1, 7, 2) :
x + = i + 2
print(x)
(a) 16 (b) 9
(c) 25 (d) Error

12. Identify the output of following code.


i=1
while (i < 10) :
print(i)
i= i*3
(a) 3 (b) 0
9 3
9
(c) 1 (d) Error
3
9

13. What will be the output of the following Python code?


i = 1
while (i < 6):
print(i)
i+= 2
if i = = 4:
break
else:
THE QUALIFIERS

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)

14. What will be the output of the following Python code?


for i in range(8):
if i = = 4:
break
else:
print(i+3)
else:
print(1)
(a) 2 (b) 3 (c) 3 (d) Error
4 4 4
6 5 5
8 6 6
1

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)

2. Python Revision Tour-II


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 of the following is/are example(s) of logical error?
(a) Identing a block to the wrong level (b) Getting operator precedence wrong
(c) Making a mistake in a boolean expression (d) All of these

2. Which of the following is false?


(a) String is mutable.
(b) capitalize() function in string is used to return a string by converting first character of
the string into uppercase.
(c) lower() function in string is used to return a string by converting the whole given string
into lowercase.
THE QUALIFIERS

(d) None of the above

3. Choose the correct option with respect to Python.


(a) Both tuples and lists are immutable.
(b) Tuples are immutable while lists are mutable.
(c) Both tuples and lists are mutable.
(d) Tuples are mutable while lists are immutable.

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 11

4. Which of the following will result in an error?


str1=“hello”
(a) print(str1[1]) (b) str1[2]=“a”
(c) print(str1[0:7]) (d) Both (b) and (c)

5. Syntax error in python is detected by................. at .............. .


(a) compiler, compile time (b) interpreter, run-time
(c) compiler, run-time (d) interpreter, compile time

6. Suppose list1 is [2, 33, 222, 14, 25], what is list1[−1] ?


(a) Error (b) None (c) 25 (d) 2

7. Suppose list1 is [3,5, 25, 1, 3], what is min(list1) ?


(a) 3 (b) 5 (c) 25 (d) 1

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

10. What will be the output of below Python code?


tup1=(1, 2, 3)
tup=tup1*2
print(tup)
(a) (2,4,6) (b) (1,2,3,1,2,3) (c) (1,1,2,2,3,3) (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

12. What will be the output of the following Python code?


x=[1, 3, 6, [18]]
y=list(x)
x[3][0]=15
x[1]=12
print(y)
THE QUALIFIERS

(a) [1,3,6, [15]] (b) [1,3,6,[12]] (c) [1,3,15,[18]] (d) [1,12,15,[18]]

13. What will be the output of the following Python code?


num = { }
num[(1,3,5)] = 18
num[(5,3,1)] = 16
num|(1,3)] = 22
sum = 0

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

14. What will be the output of following Python code?


list1=[1,2,3,4,5]
str1=“6”
for i in list1:
str1=str1+i
print(str1)
(a) 654321 (b) 123456
(c) 123645 (d) Error

15. What will be the output of following Python code?


dict1={“A”:15,“B”:23,“C”:21}
str1=“ ”
for i in dict1:
str1=str1+str(dict1[i])+“ ”
str2=str1[:−1]
print(str2[::−1])
(a) 12 32 51 (b) 12 32 15 (c) 32 21 15 (d) Error

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

2. None will return by function when


(a) return statement is not used inside a function
THE QUALIFIERS

(b) return statement is used inside a function


(c) Both (a) and (b)
(d) None of the above

3. Zero or more keyword arguments can be passed to a function in a


(a) double function call (b) any function call
(c) single function call (d) None of these

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 13

4. Which of the following function headers is correct?


(a) def myFunc(x = 2, y = 3, z): (b) def myFunc(x = 2, y, z = 3):
(c) def myFunc(x, y = 2, z = 3): (d) def myFunc(x, y, z = 3, p):

5. Which one of the following is the correct way of calling a function?


(a) function_name() (b) call function_name()
(c) ret function_name() (d) function function_name()

6. Required arguments are the arguments passed to a function in


(a) any positional order (b) correct positional order
(c) odd positional order (d) even positional order

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

8. What is the output of following code?


def test():
a=96
print(a)
a =+ 2
test()
(a) 96 (b) 98 (c) 94 (d) Error

9. What will be the output of following code?


def test(i):
i = [3]
num = [9]
test(num)
print(num)
(a) [3] (b) [9] (c) [9, 3] (d) [3, 9]

10. What is the output of following code?


val=5
def test():
global val
val=val+1
test()
val
(a) 6 (b) 5
(c) 4 (d) Error

11. Identify the output of following code.


THE QUALIFIERS

def Func(hello, num):


while(num > 0):
print(hello)
num − =1
Func(‘A’,4)
(a) AAA (b) AAAA
(c) Error (d) Infinite loop

https://t.me/cbseexamsweb
14 CBSE Sample Paper Computer Science Class XII (Term I)

12. What is the output of following code?


def func(x):
x = x + [15]
res = [11, 12, 13, 14]
func(res)
print(len(res))
(a) 5 (b) 4 (c) 3 (d) Error

13. What is the output of following code?


def myFun(a, b):
def myFun1(c, d):
return c + d
return myFun1(a, b)
return a
result = myFun(12, 13)
print(result)
(a) 13 (b) 25 (c) (12, 25) (d) Error

14. What is the output of following code?


def test(x = 2, y = 1):
x = x*y + 1
y = y* 2 − x
print(x, y)
test(y = 5, x = 3)
(a) 16 6 (b) 16 −6 (c) − 16 6 (d) 15 8

15. What is the output of following code?


def find():
l=“HELLO”
j=“ ”
l1=[]
count=1
for i in l:
if i in [‘a’, ‘e’, ‘i’, ‘o’, ‘u’]:
j=j+i.swapcase()
else:
if(count%2 !=0):
j=j+str(len(l[:count]))
else:
j=j+i
count=count+1
print(j)
THE QUALIFIERS

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

2. How do you get the current position within the file?


(a) fp.seek() (b) fp.tell() (c) fp.loc() (d) fp.pos()

3. The files that consists of human readable characters


(a) binary file (b) text file (c) Both (a) and (b) (d) None of these

4. Which function is used to write a list of string in a file?


(a) writeline() (b) writelines() (c) writestatement() (d) writefullline()

5. What will be the output of the following Python code?


myFile = None
for i in range (8):
with open(“data.txt”, “w”) as myFile:
if i > 5:
break
print(myFile.closed)
(a) True (b) False (c) None (d) Error
6. What is the use of seek() method in files?
(a) Sets the file’s current position at the offset
(b) Sets the file’s previous position at the offset
(c) Sets the file’s current position within the file
(d) None of the mentioned

7. What will be the output of the following Python code?


myFile = open(“story.txt”, “wb”)
print(“ Name of the file: ”, myFile.name)
myFile.flush()
myFile.close()
(a) Compilation error (b) Runtime error
(c) No output (d) Flushes the file when closing them
Suppose the content of the file ‘‘story.txt’’ is
Education Hub
Learning is the key of success.
8. What is the output of following code?
myfile=open(‘story.txt’,‘r’)
THE QUALIFIERS

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)

(c) Education (d) Education Hub


Hub Learning is
Learning
is
9. What is the output of following code?
f=open(‘story.txt’, ‘r’)
s=f.readline()
lcount=len(s)
print(lcount)
f.close( )
(a) 4 (b) 2 (c) 1 (d) 8

10. What is the output of following code?


f=open(‘story.txt’, ‘r’)
str=“ ”
s=0
ts=0
while str:
str=f.readline()
ts=ts+len(str)
print(ts)
f.close()
(a) 44 (b) 43 (c) 37 (d) 45

11. What is the output of following code?


def test () :
s=open (“story.txt”, “r”)
f=s.read()
z=f.split( )
count=0
for i in z:
count=count+1
print(count)
(a) 7 (b) 8 (c) 5 (d) 9
Suppose the content of file ‘‘Para.txt’’ is
Education Hub
Electronic learning
Learning is the key of success.

12. What is the output of following code?


def test() :
THE QUALIFIERS

f=open (“Para.txt”, “r”)


lines=0
l=f.readlines( )
for i in l:
if i [0] = = ‘E’ :
lines+=1
print(lines)
(a) 2 (b) 1 (c) 3 (d) Error

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 17

13. What is the output of following code?


def myFunc() :
f=open (“Para.txt”, “r”)
count=0
x=f.read()
word=x.split()
for i in word:
if (i!=“learning”):
count=count+1
print(count)
myFunc()
(a) 2 (b) 10 (c) 8 (d) Error

14. What is the output of following code?


def test():
f=open(“Para.TXT”)
n1=0
n2=0
while True:
l=f.readline()
if not l:
break
for i in l:
if (i==‘E’ or i==‘e’):
n1=n1+1
elif(i==‘C’ or i==‘c’) :
n2=n2+1
print(n1)
print(n2)
f.close()
(a) 8 (b) 8 (c) 3 (d) Error
5 4 7
15. What is the output of following code?
def Func():
with open(‘Para.txt’, ‘r’) as f :
l=f.readlines()
f.close( )
print(l)
del l[3]
print (l)
f=open (‘Para.txt’, ‘w’)
f.writelines(l)
THE QUALIFIERS

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

Answers For Detailed Solutions


1. (a) 2. (b) 3. (b) 4. (a) 5. (a)
Scan the code
6. (a) 7. (d) 8. (b) 9. (b) 10. (a)
11. (b) 12. (a) 13. (c) 14. (a) 15. (b)

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

(c) csv (d) Csv


(ii) Identify the missing code for blank space in line marked as Statement 2.
(a) “School.csv”,“w” (b) “Student.csv”,“w”
(c) “Student.csv”,“r” (d) “School.csv”,“r”
(iii) Choose the function name (with argument) that should be used in the blank space of line marked
as Statement 3.
(a) reader(fh) (b) reader(MyFile)
(c) writer(fh) (d) writer(MyFile)
(iv) Identify the suitable code for blank space in line marked as Statement 4.
(a) ‘ROLL_NO’, ‘NAME’, ‘CLASS’, ‘SECTION’ (b) ROLL_NO, NAME, CLASS, SECTION
(c) ‘roll_no’,‘name’,‘class’,‘section’ (d) roll_no,name,class,section

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

print(R[1], “ has percent = ”,R[2])


Countabove75+=1
except:
break
if Countabove75==0:
print(“There is no student who has percentage more than 75”)
average=Total/Countrec
print(“average percent of class = ”,average)
AddStudents()
GetStudents()

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

print(“I accept the offer”) #Statement 5


else:
print(“No thanks, I can find something better”) #Statement 6
On the basis of the above code, choose the right statement which will be executed when different
inputs for pay and location are given.
(i) Input: location = “Chennai”, pay = 50000
(a) Statement 1 (b) Statement 2
(c) Statement 3 (d) Statement 4
(ii) Input: location = “Surat” ,pay = 50000
(a) Statement 2 (b) Statement 4
(c) Statement 5 (d) Statement 6

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 21

(iii) Input : location = “Any Other City”, pay = 1


(a) Statement 1 (b) Statement 2
(c) Statement 4 (d) Statement 6
(iv) Input : location = “Delhi”, pay = 50000
(a) Statement 6 (b) Statement 5
(c) Statement 4 (d) Statement 3
(v) Input : location = “Lucknow”, pay = 65000
(a) Statement 2 (b) Statement 3
(c) Statement 4 (d) Statement 5

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)

(a) Code 1 Code 2


{1: ‘Thriller’, 2: ‘Mystery’, 3: {1: ‘Thriller’, 3: ‘Crime’, 4:
‘Crime’, 4: ‘Children Stories’} ‘Children Stories’}
{1: ‘Thriller’, 2: ‘Mystery’, 3: {1: ‘Thriller’, 3: ‘Crime’, 4:
‘Crime’, 4: ‘Children Stories’} ‘Children Stories’}

https://t.me/cbseexamsweb
22 CBSE Sample Paper Computer Science Class XII (Term I)

(b) Code 1 Code 2


{2:‘Mystery’} {1: ‘Thriller’, 3: ‘Crime’, 4:
‘Children Stories’}
{1: ‘Thriller’, 2: ‘Mystery’, 3: {1: ‘Thriller’, 3: ‘Crime’, 4:
‘Crime’, 4: ‘Children Stories’} ‘Children Stories’}

(c) Code 1 Code 2


{1: ‘Thriller’, 3: ‘Crime’, 4: {1: ‘Thriller’, 3: ‘Crime’, 4:
‘Children Stories’} ‘Children Stories’}
{1: ‘Thriller’, 3: ‘Crime’, 4: {1: ‘Thriller’, 2: ‘Mystery’, 3:
‘Children Stories’} ‘Crime’, 4: ‘Children Stories’}

(d) Code 1 Code 2


{1: ‘Thriller’, 3: ‘Crime’, 4: {1: ‘Thriller’, 3: ‘Crime’, 4:
‘Children Stories’} ‘Children Stories’}
{1: ‘Thriller’, 2: ‘Mystery’, 3: {1: ‘Thriller’, 3: ‘Crime’, 4:
‘Crime’, 4: ‘Children Stories’} ‘Children Stories’}

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

(a) load() (b) load(student.dat) (c) load(f) (d) load(fin)


(iv) What will be the suitable code for blank space in line marked as Statement 4.
(a) rec[0]==2 (b) rec[1]==2 (c) rec[2]==2 (d) rec[0]==1
(v) Which statement Arun should use at blank space in line marked as Statement 5 to close the file?
(a) file.close() (b) close(file) (c) f.close() (d) close()

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

reading and writing. File object points to


its beginning. existance of values of dictionary, we must
(v) seek() method moves the current file use dictionary Name. values () with in
position to a given specified position.This operator.
method does not return any value. (v) In Code 1,
3. (i) When user enters input as location = Content of dictionary Book is moving to
Chennai Library. pop () method is used to delete
key and respective value from dictionary.
and pay = 50000, then location ==
“Chennai” condition will be true. After that, So, key 2 and its value Mystery has
pay < 100000 : removed from the dictionary.
will be check it also true, so print (“No Because content is moving so dictionaries
way”) statement 2 will be execute. Library and Book both will have same
content.

https://t.me/cbseexamsweb
26 CBSE Sample Paper Computer Science Class XII (Term I)

In Code 2, 7. (i) Data type for


Content of dictionary Book is copying to Name - string (A sequence of characters)
Library. So, content of Book will remain Age - Integer (Number without decimal)
same after removing the key: value pair Items - list (ordered sequence used to store
from dictionary Library. multiple data at the same time)
5. (i) Arun should open the file in rb mode in Bill amount - float (number with decimals)
Statement 1. This mode opens a file for (ii) Nested dictionary means putting a dictonary
reading only in binary format. inside another dictionary. Nesting is of great
(ii) try is used at blank space in line marked use as kind of information, we can model in
as Statement 2. programs expanded greatly.
(iii) load (f) is used at blank space in In given condition, we can use dictionary as
Statement 3. This method is used to load dic = {Name1 : { ‘Age’ : value, ‘item
data from a binary file. list’: value, ‘bill amount’ : value},
(iv) rec[0]==1 condition will be suitable code Name2: {‘Age’ : value, ‘item list’ :
for blank space in line marked as value, ‘bill amount’ : values},
Statement 4. :.
(v) Opened file is closed by calling the
close() method of its file objects. }
So, code is f.close() where f is file object. (iii) Correct code to store information of
customers with their respective values
(vi) rec is a variable which will store the
value of pickle.load (f). Customers = {‘Paritosh’ : [24, [‘Printed
Paper’, ‘Penstand’], 3409 ]},
6. (i) Mode ‘a’ opens a file for appending. The
‘Bhavesh’ : [45, [‘A4 Rim’, ‘Printer catridge’,
file pointer is placed at the end of the file,
‘Pen carton’, ‘Gift Wrap’], 8099.99]
if the file exists. If the file does not exist,
it creates a new file for writing. (iv) To calculate the total bill amount for 15
customers, Priyank can use variable of type
(ii) csv. writer is used to insert data to the
float which store the sum of values of
CSV file. This class returns a writer object
amount at same time.
which is responsible for converting the
user’s data into a delimited string. If Priyank uses the loop to iterate the values,
variable of type float would be use to add
Syntax csv.writer (CSVfile) the bill amount.
In statement 2, missing code is So, both statements 1 and 2 are correct.
csv. writer (csvf)
8. (i) r mode is used to open the file
where, csvf is CSV file. ‘NewsLetter.TXT’. It opens a file in reading
(iii) Correct code for Statement 3 is mode.
cw. writerow ([ ‘Title’, ‘Author’, ‘Price’]) (ii) file.read( ) is used to fill the blank Statement
where, Title, Author and Price are the 2 as this method returns a string containing
columns. writerow () method is used to all characters in a file.
write single row at a time. (iii) line. split( ) method is used to fill the blank
(iv) To read a CSV file, reader () method is in Statement 3 to read data word-by-word.
used. In Statement 4, to read csvf file, the (iv) len(c)<4 is used to fill the blank in Statement
CBSE QUESTION BANK

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

Computer Applications Class 10 (Term I)


Instructions
1. This question paper is divided into three sections.
2. Section - A contains 20 questions. Attempt any 16 questions.
3. Section - B contains 20 questions. Attempt any 16 questions.
4. Section - C contains 10 questions. Attempt any 8 questions.
5. Each question carries 0.625 mark.
6. There is no negative marking.

Maximum Marks : 40 Time : 90 Minutes

Section A
This section consists of 25 questions (1 to 25). Attempt any 20 questions from this section. Choose the best
possible option.

1. Find the invalid identifier from the following.


(a) none (b) address (c) Name (d) pass

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)

4. Which of the following statement is not correct?


(a) If we try to read a text file that does not exist, an error occurs.
(b) If we try to read a text file that does not exist, the file gets created.
(c) If we try to write on a text file that does not exist, no error occurs.
(d) If we try to write on a text file that does not exist, the file gets created.

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)

8. The return type of the input() function is


(a) string (b) integer (c) list (d) tuple

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.

12. What is the significance of the tell() method?


(a) Tells the path of the file.
(b) Tells the current position of the file pointer within the file.
(c) Tells the end position within the file.
(d) Checks the existence of a file at the desired location.

13. Which of the following statement is true?


Latest CBSE SAMPLE PAPER

(a) Pickling creates an object from a sequence of bytes.


(b) Pickling is used for object serialization.
(c) Pickling is used for object deserialization.
(d) Pickling is used to manage all types of files in Python.

14. Syntax of seek() function in Python is myfile.seek(offset, reference_point) where myfile


is the file object. What is the default value of reference_point?
(a) 0 (b) 1 (c) 2 (d) 3
15. Which of the following components are part of a function header in Python?
(i) function name
(ii) return statement
(iii) parameter list
(iv) def keyword
(a) Only (i) (b) Both (i) and (iii)
(c) Both (iii) and (iv) (d) (i), (iii) and (iv)

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 29

16. Which of the following function header is correct?


(a) def cal_si(p=100, r, t=2): (b) def cal_si(p=100, r=8, t):
(c) def cal_si(p, r=8, t): (d) def cal_si(p, r=8, t=2):

17. Which of the following is the correct way to call a function?


(a) my_func() (b) def my_func()
(c) return my_func() (d) call my_func()

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.

20. Consider the following Python program:


import csv
fh = open(“Student.csv”,“r”)
stureader = csv.reader(fh)
for rec in stureader:
print(rec)
What will be the data type of rec?
(a) string (b) list
(c) tuple (d) dictionary

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

(c) .py (d) .p

23. Which of the following symbol is used in Python for comments?


(a) $ (b) @ (c) // (d) #

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)

25. Which of the following statement is false in the context of dictionary?


(a) The values of a dictionary can be accessed using keys.
(b) The keys of a dictionary can be accessed using values.
(c) Elements in a dictionary are in form of key:value pairs.
(d) Dictionaries are mutable.

Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.

26. What is the output of the following code?


T=(100)
print(T*2)
(a) Syntax error (b) (200,)
(c) 200 (d) (100,100)

27. Suppose the content of file “Myfile.txt” is


Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky

What will be the output of the following code?


myfile = open(“Myfile.txt”)
data = myfile.readlines()
print(len(data))
myfile.close()
(a) 3 (b) 4
(c) 106 (d) 22

28. Identify the output of the following Python statement.


x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
y = x[1][2]
print(y)
(a) 11.0 (b) 12.0 (c) 14.0 (d) 15.0
Latest CBSE SAMPLE PAPER

29. Identify the output of the following Python statement.


x = 2
while x < 9:
print(x, end=‘ ’)
x = x + 1
(a) 12345678 (b) 3456789
(c) 2345678 (d) 23456789

30. Identify the output of the following Python statement.


b = 1
for a in range(1, 10, 2):
b += a + 2
print(b)
(a) 31 (b) 33 (c) 36 (d) 39

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 31

31. Identify the output of the following Python statement.


lst1 = [10, 15, 20, 25, 30]
lst1.insert( 3, 4)
lst1.insert( 2, 3)
print (lst1[-5])
(a) 2 (b) 3 (c) 4 (d) 20

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

34. What will be the output of the following Python code?


def add (num1, num2):
sum = num1 + num2
sum = add(20,30)
print(sum)
(a) 50 (b) 0 (c) Null (d) None

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

36. What will be the output of the following code?


def my_func(var1=100, var2=200):
var1+=10
var2 = var2 - 10
return var1+var2
print(my_func(50),my_func())
(a) 100 200 (b) 150 300 (c) 250 75 (d) 250 300

37. What will be the output of the following code?


value = 50
def display(N):
global value
value = 25
if N%7==0:
value = value + N
else:
value = value - N
print(value, end=“#”)
display(20)
print(value)
(a) 50#50 (b) 50#5
(c) 50#30 (d) 5#50#

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

39. What is the output of the following code snippet?


def ChangeVal(M,N):
for i in range(N):
if M[i]%5 == 0:
M[i]//=5
if M[i]%3 == 0:
M[i]//=3
L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end=“#”)
(a) 5#8#15#4# (b) 5#8#5#4#
(c) 5#8#15#14# (d) 5#18#15#4#

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 33

40. Suppose the content of file ‘‘Myfile.txt’’ is


Humpty Dumpty sat on a wall
Humpty Dumpty had a great fall
All the king's horses and all the king's men
Couldn't put Humpty together again
What will be the output of the following code?
myfile = open(“Myfile.txt”)
record = myfile.read().split()
print(len(record))
myfile.close()
(a) 24 (b) 25 (c) 26 (d) 27

41. Find the output of the following code:


Name=“PythoN3@1”
R=“ ”
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+“#”
print(R)
(a) pYTHOn##@ (b) pYTHOnN#@ (c) pYTHOn#@ (d) pYTHOnN@#

42. Suppose the content of file “Myfile.txt” is


Honesty is the best policy.

What will be the output of the following code?


myfile = open(“Myfile.txt”)
x = myfile.read()
print(len(x))
Latest CBSE SAMPLE PAPER

myfile.close()
(a) 5 (b) 25 (c) 26 (d) 27

43. Suppose the content of file “Myfile.txt” is


Humpty DUMPTY sat on a wall
Humpty DUMPTY had a great fall
All the king’s horses and all the king's men
Couldn’t put Humpty together again
What will be the output of the following code?
myfile = open(“Myfile.txt”)
x = myfile.read().lower()
y = x.count(‘umpty’)
print(y)
myfile.close()
(a) 2 (b) 3 (c) 4 (d) 5

https://t.me/cbseexamsweb
34 CBSE Sample Paper Computer Science Class XII (Term I)

44. What will be the output of the following code?


x = 3
def myfunc():
global x
x+=2
print(x, end=‘ ’)
print(x, end=‘ ’)
myfunc()
print(x, end=‘ ’)
(a) 3 3 3 (b) 3 5 3
(c) 3 3 5 (d) 3 5 5

45. Suppose the content of file “Myfile.txt” is


Ek Bharat Shreshtha Bharat

What will be the output of the following code?


myfile = open(“Myfile.txt”)
vlist = list(“aeiouAEIOU”)
vc=0
x = myfile.read()
for y in x:
if(y in vlist):
vc+=1
print(vc)
myfile.close()
(a) 6 (b) 7
(c) 8 (d) 9

46. Suppose the content of file “Myfile.txt” is


Twinkle twinkle little star
How I wonder what you are
Up above the world so high
Like a diamond in the sky
Twinkle twinkle little star
Latest CBSE SAMPLE PAPER

What will be the output of the following code?


myfile = open(“Myfile.txt”)
line_count = 0
data = myfile.readlines()
for line in data:
if line[0] == ‘T’:
line_count += 1
print(line_count)
myfile.close()
(a) 2 (b) 3
(c) 4 (d) 5

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 35

47. Consider the following directory structure:

Suppose root directory (School:\) and present working directory are the same. What
will be the absolute path of the file ‘Syllabus.jpg’?
(a) School/Syllabus.jpg (b) School/Academics/Syllabus.jpg
(c) School/Academics/../Syllabus.jpg (d) School/Examination/Syllabus.jpg

48. Assume the content of the text file “Myfile.txt” is


Arjun Kumar
Ismail Khan
Joseph B
Hanika Kiran

What will be the data type of data_rec?


myfile = open(“Myfile.txt”)
data_rec = myfile.readlines()
myfile.close()
(a) string (b) list
(c) tuple (d) dictionary

49. What will be the output of the following code?


tup1 = (1,2,[1,2],3)
tup1[2][1]=3.14
print(tup1)
(a) (1,2,[3.14,2],3) (b) (1,2,[1,3.14],3)
(c) (1,2,[1,2],3.14) (d) Error message

Section C
Latest CBSE SAMPLE PAPER

This section consists of 6 questions (50 to 55). Attempt any 5 questions.


Rohit, a student of Class 12th, is learning csv module in Python. During the examination,
he has been given a stub Python program (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

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

54. Identify the suitable code for blank space in Statement 5.


(a) data (b) record
(c) rec (d) insert

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.

1. …… is a logical instructions, which Python interpreter can read and execute.


(a) Expression (b) Statement (c) Comment (d) Identation

2. Which comments start with # symbol?


(a) Double line (b) Multi-line (c) Single line (d) All of these

3. Which data type contains only numeric value in Python?


(a) Numbers (b) Strings (c) Lists (d) Tuples

4. Index of ……… refers to first element.


(a) 1 (b) − 1 (c) 0 (d) n+1
SAMPLE PAPER 1

5. This function is used to calculate total occurrence of given elements of list.


(a) len() (b) sum() (c) count() (d) extend()

6. Which of the following is a collection of Python objects separated by commas


represent as (,)?
(a) List (b) Tuple (c) Dictionary (d) String

7. ……… a tuple is a technique to access an individual element of that tuple.


(a) Comparing (b) Accessing (c) Concatenation (d) Traversing

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

9. …… are used to pass the value of a variable to a function.


(a) Arguments (b) Parentheses (c) Classes (d) Objects

10. non-void functions are also known as


(a) non functions (b) valid functions (c) fruitful functions (d) invalid functions

11. A variable declared in a block is local to that block and is known as


(a) global variable (b) local variable (c) multi variable (d) single variable

12. What is the mean of L in LEGB rule for scope resolution?


(a) Local (b) Last (c) Least (d) Library

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

15. ……… method takes a string and writes it in the file.


(a) writelines() (b) write() (c) writerow() (d) writer()

16. For readline(), a line is terminated by


(a) ‘\n’ (b) EOF (c) Either (a) or (b) (d) None of these

17. Which of the following is true regarding lists in Python?


(a) Lists are immutable.
(b) Size of the lists must be specified before its initialisation.
(c) Elements of lists are stored in contagious memory location.
(d) size(list1) command is used to find the size of lists.

18. Suppose list1 is [56, 89, 75, 65, 99], what is the output of list1 [− 2]?
(a) Error (b) 75 (c) 99 (d) 65

19. Which one of the following is correct?


(a) In Python, a dictionary can have two same keys with different values.
(b) In Python, a dictionary can have two same values with different keys.
(c) In Python, a dictionary can have two same keys or same values but cannot have two
same keys-value pair.
(d) In Python, a dictionary can neither have two same keys nor two same values.

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

21. Which of these about a dictionary is false?


(a) The values of a dictionary can be accessed using keys.
(b) The keys of a dictionary can be accessed using values.
(c) Dictionaries are not ordered.
(d) Dictionaries are mutable.

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

23. Which of the following will result in an error?


str1=“python”
(a) print(str1[3]) (b) str1[1]=“xyz” (c) print(str1[1:5]) (d) Both (b) and (c)

24. Which of the following is false?


(a) String is immutable.
(b) capitalize() function in string is used to return a string by converting the whole given
string into uppercase.
(c) lower() function in string is used to return a string by converting the whole given string
into lowercase.
(d) None of the above

25. What will be the following Python code return?


str1=“Stack of books”
print(len(str1))
(a) 13 (b) 14 (c) 15 (d) 16

Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.

26. What is the output of following code?


L = [34, 89]
print(L*3)
(a) Syntax error (b) [34, 89, 34, 89, 34, 89] (c) [102, 267] (d) [37, 92]

27. Suppose the content of file ‘‘para.txt’’ is


Hello…How are you?
Hi…I am fine.
What are you doing now?
Hmm… nothing special.
What will be the output of following code?
myfile = open(“para.txt”,“r”)
s = myfile.read(15)
print(s)
myfile.close()
SAMPLE PAPER 1

(a) Hello…How are (b) Hello…How are you?


(c) Hello…How are yo (d) Hello…How are you?
Hi
28. Identify the output of the following Python statement.
def test(a,b):
s = a+b*2
print(s)
test(12,5)
(a) 34 (b) 17 (c) 22 (d) 29

https://t.me/cbseexamsweb
46 CBSE Sample Paper Computer Science Class XII (Term I)

29. How many times will the given loop iterate?


i = 0
while(i<25):
print(“Python”)
i = i + 1
(a) 24 (b) 25 (c) 26 (d) None of these

30 Find the output of the following code.


i=1
while (i<15):
print(i)
i = i*2
(a) 1 (b) 2 (c) 1 (d) 2
2 4 2 4
4 6 4 8
6 8 8
8 10
10 12
12 14
14

31. Identify the output of the following Python statement.


list1=[4,3,7,9,15,0,3,2]
s = list1[2:5]
print(s)
(a) [7,9,15,0] (b) [3,7,9,15] (c) [7,9,15] (d) [7,9,15,0,3]

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

33. Observe the code.


def insert():
import pickle
file1 = open(‘college.txt’.‘a’)
while True:
y = input(“Enter something”)
pickle.dump(y,file1)
SAMPLE PAPER 1

ans = input(“Want to enter more data Y/N”)


if(ans.upper()= = ‘N’):
_______ #Line1
file1.close()
insert()
Above code is used to insert element or data into an existing text file.
Write appropriate jump statement from the following to insert the element and
terminate the program whenever is need.
(a) jump (b) continue (c) goto (d) break

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 47

34. What will be the output of the following Python code?


a = 3
b = 4
c = a**b+5
print(c)
(a) 17 (b) 86 (c) 14 (d) None of these

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

36. Identify the output of following code.


List1=[1, 2, 3, 7, 9]
L=List1.pop(9)
print(L)
(a) Syntax error (b) 9 (c) [1, 2, 3, 7] (d) None of these

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#

38. What is the output of the following code?


def compute(a,b):
if a > b:
smaller = b
else:
smaller = a
for i in range (1, smaller+1):
if((a%i= = 0) and (b% i ==0)):
val = i
return val
compute(54,24)
(a) 216 (b) 108 (c) 6 (d) 3

39. What is the output of the following code snippet?


def test(a):
SAMPLE PAPER 1

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)

40. Find the output of following code.


def display (num) :
num.append ([27])
return (num[1], num[2], num[3])
list1= [6, 12, 27]
n1, n2, n3 = display (list1)
print (list1)
(a) [6,12,27] (b) [6,12, 27, [27]] (c) [[27], 6, 12, 27] (d) [6, 12, [27], 27]

41. What will be the output of the following Python code?


x = [‘ab’, ‘cd’]
for i in x:
i.upper()
print(x)
(a) [‘ab‘, ‘cd’] (b) [‘AB’, ‘CD’]
(c) [None, None] (d) None of the mentioned

42. Suppose the content of file ‘‘para.txt’’ is


Hello…How are you?
Hi…I am fine.
What are you doing now?
Hmm…nothing special.

What will be the output of following code?


def count():
f = open (“para.txt”,“r”)
lines = 0
l = f.readlines()
for i in l:
if i[0] = = ‘H’:
lines+=1
print(lines)
(a) 4 (b) 2 (c) 3 (d) None of these

43. Suppose the content of file ‘‘para.txt’’ is


If life were predictable it would cease to be life, and be without flavor.

What will be the output of following code?


file = open(“para.txt”, “r”)
a = file.read()
b = a.count(‘life’)
print(b)
SAMPLE PAPER 1

file.close()
(a) 2 (b) 3 (c) 4 (d) 5

44. Observe the code and identify the output.


x =5
def func2 ():
x =3
global x
x =x + 1

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

45. The content of file ‘arihant.txt’ is as follows:


Welcome to Arihant!
Welcome to your one-step solutions for all your study, practice and assessment
needs for various competitive & recruitment examinations and school segment.

What will be the output of following code?


myfile = open(‘arihant.txt’,‘r’)
s = myfile.read(15)
print(s)
myfile.close()
(a) Welcome to Arihan (b) Welcome to Arih
(c) Welcome to Arihant (d) Welcome to Arihant!

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

What will be the output of following code?


f = open(‘student.txt’,‘r’)
s = f.readlines()
lcount = len(s)
print(lcount)
f.close()
(a) 4 (b) 3 (c) 2 (d) 5

47. Consider the following directory structure.


ABC

Hello

Mode. png

Identify the root directory.


SAMPLE PAPER 1

(a) Hello (b) ABC


(c) Mode.png (d) None of these

48. Assume the content of text file ‘‘student. txt’’ is


Sumita Sharma
Abhinav
Naman Kumar
Neha Verma
Khushi Sinha

https://t.me/cbseexamsweb
50 CBSE Sample Paper Computer Science Class XII (Term I)

What will be the datatype of s?


file = open(“student.txt”)
s = file.readlines()
file.close()
(a) list (b) string (c) tuple (d) dictionary

49. What will be the output of following code?


sub = “PYTHON”
for i in sub:
print(i, ‘ ’, end = “ ”)
(a) P (b) PYTHON (c) P Y T H O N (d) P, Y, T, H, O, N
Y
T
H
O
N

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

50. Which value will be assign to variable i in line 1 as marked ?


(a) 1 (b) 0 (c) True (d) False
51. Choose the correct option to fill up the blank in line 2 as marked.
(a) i == mid: (b) i > mid: (c) i < mid: (d) i < = mid:
SAMPLE PAPER 1

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.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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

27. ‘‘para.txt’’ is a text file that contains some 35. x= 10*3//4+5//4+4−10+5//6


content. This program will read the data or = 30//4+5//4+4−10+5//6
15 bytes from starting. This will also include = 7+5//4+4−10+5//6
space and special characters.
= 7+1+4−10+5//6
28. test() is a function, which has some code and = 7+1+4−10+0 = 8+4−10+0
this code or statement execute when function
test() will be called. a and b are arguments of = 12−10+0 = 2+0 =2
test() function, so during called the function, it 36. In pop(9), parentheses put index number
must to give the value of arguments. instead of element. In the given list, maximum
When arguments are 12 and 5, then index number is 4, then 9 is out of index range.
a = 12, b = 5 37. randint() method returns a random. So, it will
s = a + b * 2 = 12 + 5 * 2 = 12 + 10 = 22 give syntax error integer value between the
29. while() loop tests for its ending condition two higher and lower limits provided as two
before executing the statements enclosed in the parameters. So, the output will in between 3 to
loop body even the first time. 5 because its lower index number and upper
index number are 1 and 4, respectively.
In this code, value of i is 0 and while has
condition i<25 that means the value of i will be 38. if 54>24 true, smaller = 24
from 0 to 24. So, this loop will be iterate 25 for loop go from 1 to 24 in which 1, 2, 3, 6
times. numbers will divide both given numbers a=54
30. while() loop will go from 1 to 14, then value of and b=24.
i is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14. From the factors, 6 is greatest or last value. So,
i i*2 i<15 the output is 6.
1 1*2=2 2<15 True 39. test() is a function in which we pass an
2 2*2=4 4<15 True argument. for loop will be start from i. i.e.
4 4*2=8 8<15 True 0(default value of index) to the length of
passing argument.
8 8*2=16 16<15 False
Output 1 40. append() method in Python adds a single item
to the existing list at the end. In given code,
2
list1 is [6, 12, 27] and appending an element
4 ([27]). So, list1 will be [6,12,27,[27]].
8
41. The function upper() does not modify a string
31. : is performed the slice operation. Slicing refers in place, it returns a new string which is not
to access a specific portion or a subset of list for being stored anywhere.
some operation while the original list remains
42. This program will display the number of lines
unaffected.
starting with ‘H’ in the file ‘‘para.txt’’.
Indexing of the list is started from 0, so the
It will read the file line by line and check the
value of index 2 is 7 and next index is 5, then
condition if i[0]= = ‘H’, when it is true, then
values will consider index no. 2 to index no. 4.
variable lines add 1 in its value.
i.e. 7, 9, 15.
43. This program will display the number of word
32. Mydata is a text file on which we need to write ‘life’. It opens file ‘para.txt’ and read the data
data “ABC”. write() method takes a string and and counts the ‘life’ word with count() method
writes it into the file. So, to write the data into and assigned its value to b. Then finally print
SAMPLE PAPER 1

text file, the code is File.write(“ABC”). the value of b, i.e. 2.


33. break statement alters the normal flow of 44. In the given code, the statement succeeding the
execution as it terminates the current loop and
statement global x informs Python to
resumes execution of the statement following
increment the global variable x.
that loop.
Hence, the output is 6. i.e. 5 + 1, which is also
34. **is an exponent operator, which returns first the value for global x. When x is reassigned
raised to power second. with the value 3 the local x hides the global x
c= a**b+5 and hence 3 is printed.
= 3**4+5 So, final output is 6
= 81+5 =86 3

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.

1. Which is a way to convey a Python object into a character stream.


(a) Pickling (b) Unpickling (c) dump() method (d) load() method

2. Which character is used to create a new file in csv?


(a) r (b) w (c) r+ (d) x

3. Which path does not start with a leading forward slash?


(a) Relative (b) Absolute (c) Both (a) and (b) (d) None of these

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

(c) Comparison operators (d) All of these

5. This function converts all uppercase letters in string to lowercase letters.


(a) upper() (b) lower() (c) isupper() (d) islower()

6. List can be created to put the elements in


(a) [] (b) {} (c) () (d) None of these

7. Which of the following are sequence of character data?


(a) Lists (b) Tuples (c) Strings (d) Dictionaries

https://t.me/cbseexamsweb
56 CBSE Sample Paper Computer Science Class XII (Term I)

8. List, dictionary and sets are


(a) mutable (b) immutable (c) Both (a) and (b) (d) None of these

9. The process of converting a data type into another data type is known as ............ .
(a) expression (b) operator
(c) type conversion (d) comparison

10. In complex number a + ib, b represents as


(a) real part (b) imaginary part
(c) special part (d) None of these

11. To print all elements of tuple in reverse order using ............


(a) [: – 1] (b) [: : – 1] (c) [1 : : ] (d) [: : 1]

12. Which function is used to convert string into tuple?


(a) string() (b) tup() (c) tuple() (d) str_tuple()

13. Which statement is a sequence of more than one statements?


(a) Control statement (b) Compound statement
(c) Single statement (d) Sequence statement

14. Which of the following is a step-by-step process of solving a well defined


computational problem?
(a) Algorithm (b) Pseudocode (c) Flowchart (d) Decision table

15. ............ are drawn using certain special purpose symbols.


(a) Algorithm (b) Pseudocode
(c) Flowchart (d) Decision table

16. Which of the following function is a built-in function in Python?


(a) myFunc() (b) test() (c) def() (d) print()

17. What will be the output of the following Python expression?


round(8.695)
(a) 8.6 (b) 9 (c) 8 (d) 8.7

18. What will be the output of the following Python code?


x = [‘AB’, ‘CD’]
for i in x:
i.lower()
print(x)
(a) [‘ab’, ‘cd’] (b) [‘AB’, ‘CD’]
(c) [None, None] (d) None of the mentioned
SAMPLE PAPER 2

19. Suppose list1 is [2445,133,12454,123], what is max(list1)?


(a) 2445 (b) 133 (c) 12454 (d)123

20. What will be the output of the following Python code?


x = “abcdef”
i = “a”
while i in x:
print(‘i’, end = “ ”)
(a) No output (b) i i i i i i ... (c) a a a a a a... (d) a b c d e f

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

22. What will be the output of the following Python code?


>>> a=(l,2,(4,5))
>>> b=(l,2,(3,4))
>>> a<b
(a) False
(b) True
(c) Error, < operator is not valid for tuples.
(d) Error, < operator is valid for tuples but not if there are sub-tuples.

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

24. What will be the output of the following Python code?


Dic1={}
Dic1[2]=85
Dic1[1]=[22,23,24]
print(Dic1[1][1])
(a) [22,23,24] (b) 23 (c) 22 (d) Error

25. What will be the output of the following Python code?


dic1 = {0: ‘One’, 1: ‘Two’, 2: ‘Three’}
for x, y in dic1:
print(x, y)
(a) 0 1 2 (b) One Two Three
(c) 0 One 1 Two 2 Three (d) Error

Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.

26. What is the output of the following code?


t1=(70, 56, ‘Hello’, 22, 2, ‘Hi’, ‘The’, ‘World’, 3)
print(t1 [2:4])
(a) (56, ‘Hello’) (b) (‘Hello’, 22)
SAMPLE PAPER 2

(c) (‘Hello’, 22,2) (d) (56, ‘Hello’, 22)

27. Suppose the content of file ‘‘arihant.txt’’ is


Welcome to Arihant!
Welcome to your one-step solutions for all your study, practice and
assessment needs for various competitive & recruitment examinations
and school segment.

https://t.me/cbseexamsweb
58 CBSE Sample Paper Computer Science Class XII (Term I)

What will be the output of the following code?


myfile=open(“arihant.txt”,“r”)
s=myfile.read(10)
print(s)
s1=myfile.read(15)
print(s1)
myfile.close()
(a) Welcome to (b) Welcome to
Welc Arihant!
(c) Welcome to (d) Welcome
Arihant! to
Welc Arihant

28. Identify the output of following code.


for i in range(4):
if i == 4:
break
else:
print(i)
else:
print(“Welcome”)
(a) 0 (b) 1 (c) Error (d) None
1 2
2 3
3 Welcome
Welcome

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

30. Identify the output of the following Python statement.


x=0
for i in range (1, 12, 3):
x+=i+3
print(x)
(a) 31 (b) 32 (c) 33 (d) 34
SAMPLE PAPER 2

31. Identify the output of the following Python code.


def test(val):
val[1]=20
a=[2, 3, 4]
test(a)
print(a)
(a) [2, 20] (b) [20, 3] (c) [2, 3, 20, 4] (d) [2, 20, 4]

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)

33. Suppose the content of file “vowel.txt” is


Welcome to Arihant!
Welcome to your one-step solutions for all your study, practice and
assessment needs for various competitive & recruitment
examinations and school segment.

What will be the output of following code?


def count():
vow=0
f=open(“vowel.text”, “r”)
N=f.read()
M=N.split()
for i in M:
if(i==“a” or i== “e” or i==“i” or i==“o” or i==“u”):
vow=vow+1
f.close()
(a) 60 (b) 58 (c) 59 (d) 54

34. Find the output of the following code.


def Func (a = 1, b = 2):
a = a+ b
b + = 1
print (a , b)
Func (b = 4, a = 5)
(a) 9 5 (b) 4 5
(c) 4 9 (d) Error

35. Evaluate the following expression and identify the correct answer.
SAMPLE PAPER 2

2*3//4 + 4//4 + 8 − 2 + 5//8


(a) 14 (b) 8
(c) 10 (d) 12

36. What will be the output of the following Python code?


def power(a, b=4):
r = 1
for i in range(b):
r = r * a
return r

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

37. What will be the output of the following Python code?


def printMax(a, b):
if a> b:
print(a, ‘is maximum’)
elif a == b:
print(a, ‘is equal to’, b)
else:
print(b, ‘is maximum’)
printMax(33,94)
(a) 33 is maximum (b) 94
(c) 94 is maximum (d) Error

38. What will be the output of following code?


import random
AR=[20,30,40,50,60,70]
Lower =random.randint(1,3)
Upper =random.randint(2,4)
for K in range(Lower, Upper +1):
print(AR[K],end=“#”)
(a) 10#40#70# (b) 30#40#50#
(c) 50#60#70# (d)40#50#70#

39. What will be the output of the following Python code?


list1 = [11, 12, 13, 14, 15]
for i in range(1, 5):
list1[i−1] = list1[i]
for i in range(O, 5):
print(list1[i] ,end = “ ”)
(a) 15 15 1112 13 (b) 15 1112 13 14
(c) 12 13 14 15 11 (d) 12 13 14 15 15

40. What will be the output of the following Python code?


myFile = open(“story.txt”, “wb”)
print (“Name of the file:”, myFile.name)
myFile.flush()
myFile.close()
SAMPLE PAPER 2

(a) Compilation error (b) Runtime error


(c) No output (d) Flushes the file when closing them

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

42. Suppose the content of file ‘‘para.txt’’ is


Nothing is more terrifying than fearlessness

What will be the output of the following code?


file = open(“para.txt”)
val = file.read()
print(len(val))
file.close()
(a) 44 (b) 39 (c) 45 (d) Error

43. What will be the output of following code?


def mean (* args):
total = 0.0
for v in args :
total + = v
return (total / len (args))
mean (* [1, 2, 3, 4])
(a) 2 (b) 3 (c) 2.5 (d) 3.5

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

What will be the output of the following code?


def COUNT ( ):
s=open (“Quotes.txt”, “r”)
f=s.read( )
z=f.split( )
count=0
SAMPLE PAPER 2

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

46. What will be the output of the following Python code?


i=0
def change(i):
i=i+1
return i
change(1)
print(i)
(a) 1 (b) Nothing is displayed (c) 0 (d) Error

47. What is the output of the code?


z = 100
def f():
global z
print(‘z is:’, z)
z=50
print(‘New value of global z is:’, z)
f()
print(‘Value of z is:’, z)
(a) z is : 100
New value of global z is: 100
Value of z is : 100
(b) z is : 100
New value of global z is: 100
Value of z is : 50
(c) z is : 100
New value of global z is: 50
Value of z is : 100
(d) z is : 100
New value of global z is: 50
Value of z is : 50
SAMPLE PAPER 2

48. Suppose the content of text file ‘‘para.txt‘’ is


Muskan Verma
Rahul Sinha
Arihant
What will be the data type of s?
file=open (“para.txt”, “r”)
s=file.read()
file.close()
(a) string (b) list (c) tuple (d) sets

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 63

49. What will be the output of the following code?


dic1= {‘One’ :1, ‘Two’ : 2, ‘Three’:3}
s=(list(dic1.values())
print(s)
(a) [‘One’, ‘Two’, ‘Three’] (b) [1, 2, 3]
(c) [3] (d) [‘One’ : 1, ‘Two’ : 2, ‘Three’ : 3]

Section C
(Case Study Based Questions)
This section consists of 6 questions (50 to 55). Attempt any 5 questions.

def makenew (mystr):


newstr = “ ”
count = 0
for i in ____ : #line 1
if count % 2 ! = 0 :
newstr = newstr + str (____) #line 2
else:
if ____ (i): #line 3
newstr = newstr + upper(i)
else:
newstr = newstr + ____ #line 4
count + = 1
newstr = ____ + mystr[: 1] #line 5
print (“The new string is:”, newstr)
____ (“sTUdeNT”) #line 6
50. Choose the correct option to fill up the blank in line 1 as marked.
(a) mystr (b) newstr (c) mystr +1 (d) mystr −1

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

(a) newstr (b) count (c) i (d) str

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.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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

23. Arithmetic operator ‘>’ cannot be used with


using [: : −1]. Tuple holds a sequence of
dictionaries.
heterogeneous elements, it stores a fixed set of
elements and do not allow changes. 24. Now, Dic1={85:[22,23,24],2:1}. Dic1[1][1] refers
to second element having key on position 1,
12. tuple() function is used to convert string into
i.e. 23.
tuple.
25. It will give Error, because objects of type int
13. Compound statement is a sequence of more
are not iterable.
than one statements.
26. : is a slice operator, which returns the sub-part
14. Algorithm is a step-by-step process of solving
of any data type as string, list, tuple etc. Index
a well defined computational problem. number is started from 0, so the value of index

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.

1. Which of the following is/are character set?


(a) Alphabets (b) Digits (c) White space (d) All of these

2. Which of the following are the most obvious kind of constants?


(a) Keywords (b) Literals (c) Variables (d) Identifiers

3. These operators are used to make a decision on two conditions.


(a) Logical (b) Arithmetic
(c) Relational (d) Assignment
SAMPLE PAPER 3

4. String literals in Python are enclosed by ............ .


(a) double quotes (b) single quotes
(c) Both (a) and (b) (d) None of these

5. Which index number is used to represent last character of string?


(a) − 1 (b) 1 (c) 0 (d) n − 1

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

7. file. mode attribute is used to


(a) store access mode (b) traverse mode
(c) return access mode (d) All of these

8. This method is used to write a string into the file.


(a) writelines() (b) write()
(c) writerow() (d) writer()

9. Which of the following is/are used as line termination for readline()?


(a) ‘\n’ (b) EOF
(c) Either (a) or (b) (d) None of these

10. Serialization process is also called


(a) pickling (b) unpickling
(c) dump() method (d) load() method

11. This character is used in CSV file.


(a) rb (b) wb (c) rb + (d) x

12. Which of the following is related to working directory?


(a) Relative (b) Absolute (c) Both (a) and (b) (d) None of these

13. The def keyword is followed by the function name and


(a) parameter (b) argument (c) parenthesis (d) classes

14. To add a new element to a list, which command will we use?


(a) list1.add(8) (b) list1.append(8)
(c) list1.addLast(8) (d) list1.addEnd(8)

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)

16. If a=(11,12,13,14), a[1:−1] is………


(a) (12,13) (b) [12,13]
(c) (12,13,14) (d) error, tuple slicing does not exist

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

18. What will be the value of x in the following Python expression?


x=int(43.55+2/2)
(a) 43 (b) 44
(c) 22 (d) 23

19. Which of the following will run without error?


(a) round(65.8) (b) round(1265.983,2,4)
(c) round() (d) round(6529.123,2,l)

https://t.me/cbseexamsweb
70 CBSE Sample Paper Computer Science Class XII (Term I)

20. Which of these definitions correctly describe a module?


(a) Denoted by triple quotes for providing the specification of certain program elements
(b) Design and implementation of specific functionality to be incorporated into a program
(c) Defines the specification of how it is to be used
(d) Any program that reuses code

21. Which of the following is not a valid namespace?


(a) Global namespace (b) Public namespace (c) Built-in namespace (d) Local namespace

22. What is the use of tell() method in Python?


(a) Tells you the current position within the file
(b) Tells you the end position within the file
(c) Tells you the file is opened or not
(d) None of the above

23. Which of the following mode will refer to binary data?


(a) r (b) w (c) + (d) b

24. Correct syntax of file.writelines() is


(a) file.writelines(sequence) (b) fileObject.writelines()
(c) fileObject.writelines(sequence) (d) None of these

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.

26. Find the output of the following code.


dict = {}
a, b, c = 15, 25, 35
dict[a, b, c] = a + b – c
a, b, c = 25, 20, 40
dict[a, b, c] = a + b – c
print(dict)
(a) {(15, 25, 35) : 5, (25, 20, 40) : 5}
(b) {(15, 25, 35), (25, 20, 40)}
(c) {15, 25, 35, 25, 20, 40}
(d) Error
SAMPLE PAPER 3

27. What will be printed on the console by the below code?


x, y, z, k, j = 9, 7, 2, 2, 1
m = 5
if (x > y):
if (y > z and y > k):
m = m – 1
else:
k = k + 1

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

28. Write the output of the following code.


number = 2
def Fun ():
number = 5
print(“Number(s):”)
print(number)
Fun()
print(number)
(a) 5 (b) Number (c) Number(s) (d) number(s)
2 5 5 2
2 2 5

29. What will be the output of the following Python code?


i = 1
while True:
if i%5 == 0:
break
print(i)
i += 1
(a) 1 (b) 1 (c) 1 (d) Error
2 2 2
3 3
4

30. What will be the output of the following Python code?


str1 = “be honest”
for i in str1.split():
print(i, end=“, ”)
(a) b, e, , h, o, n, e, s, t, (b) b, e,, h, o, n, e, s, t
(c) be, honest, (d) Error

31. What will be the output of the following Python code?


SAMPLE PAPER 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)

32. What will be display by this file?


import os
f=‘computer.txt’
p=os.path.abspath(f)
print(p)
(a) File name
(b) Complete path
(c) File name with directory name
(d) File name with folder name

33. What will be the output of following code?


def count():
v=0
f=open(“para.txt”, “r”)
N=f.read()
M=N.split()
for i in M:
if (i!=“a” or i!= “e” or i!=“i” or i!=“o” or i!=“u”):
print(i)
v=v+1
f.close()
print(v)
If content of file ‘‘para.txt’’ is
Arihant Publication

(a) 11 (b) 7 (c) 18 (d) 19

34. What will be the output of following code?


def Readfile():
i=open(“Employee.dat”,“rb+”)
x=i.readline()
while(x):
l=x.split(‘:’)
if(20000>=float(l[2])<=40000):
print(x)
x=i.readline()
(a) Display details of employees who are earning between 20000 and 40000 (both are
exclusive)
(b) Display details of employees who are earning between 20000 and 40000 (both are
SAMPLE PAPER 3

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

37. What will be the output of the following Python code?


tup1=[(56, 89),(36,66),(88, 69)]
s = tup1.sort()
print(s)
(a) [(36, 66), (56, 89), (88, 69)]
(b) [(56, 89),(36,66),(88, 69)]
(c) Error because tuples are immutable
(d) Error because tuple has no sort attribute

38. What will be the output of the following Python code?


def sum(*args):
‘‘‘Function returns the sum of all values’’’
r = 0
for i in args:
r += i
return r
print(sum._doc)
print(sum(5, 8, 3))
print(sum(2, 6, 3, 4, 1))
(a) None (b) 16 (c) None (d) Error
16 16 16
16

39. What will be the output of the following Python code?


x=2
def test():
global x
x=x+1
test()
print(x)
(a) 2 (b) 1 (c) 0 (d) 3
SAMPLE PAPER 3

40. What will be the output of the following Python code?


i = 0
while i < 10:
print(i)
i += 2
if i == 8:
break
else:
print(0)

https://t.me/cbseexamsweb
74 CBSE Sample Paper Computer Science Class XII (Term I)

(a) 0 (b) 1 (c) 0 (d) 1


2 2 2 2
4 4 4 3
6 6 6 4
8 5
6
7
8

41. What is the output of the following code snippet?


import random
AR=[20,30,40,50,60,70];
FROM=random.randint(1,3)
TO=random.randint(2,4)
for K in range(FROM,TO+1):
print(AR[K],end=“#”)
(a) 10#40#70# (b) 30#40#50#
(c) 50#60#70# (d) 40#50#70#

42. What is the output of the following code snippet?


To=5
for K in range(O,To) :
if K%4==0:
print (K*4)
else:
print (K+3)
(a) 4 (b) 0 (c) 0 (d) 5
5 4 4 6
6 6 5 16
16 16 6
16

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

(a) 20 (b) 35 (c) 10 (d) 15

44. What will be the output of the following code?


def DISPLAYWORDS():
c=O
file=open(‘STORY.TXT’,‘r’)
line = file.read()
word = line.split()
for w in word:

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

45. What will be the output of the following Python code?


a=[18,23,69,[73]]
b=list(a)
a[3][0]=110
a[1]=34
print(b)
(a) [18,34,69,[110]] (b) [18,23,69,[73]]
(c) [18,23,69,[110]] (d) [18,34,69,[73]]

46. What will be the output of the following Python code?


list1=[9, 5, 3, 5, 4]
list1[1:2]=[7,8]
print(list1)
(a) [9,5, 3, 7, 8] (b) [9, 7, 8, 3, 5, 4]
(c) [9,[ 7, 8], 3, 5,4] (d) Error

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

48. What will be the output of following code?


f=open(“student.txt”,“r”)
str=f.read()
s=len(str)
SAMPLE PAPER 3

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)

49. What will be the output of the following code?


t1=(2, 5,[1,2], 9)
t1[2][1]=11
print(t1)
(a) (2, 5, [11, 2], 9) (b) (2, 5, [1, 2], 11) (c) (2, 5, [1, 11], 9) (d) Error

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

50. Which condition will be satisfy in while loop in line 1 as marked?


(a) Flag (b) False (c) True (d) None

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

53. Which condition will be used in elif ?


(a) i == N or i == n (b) i == ‘N’ or i == ‘n’
SAMPLE PAPER 3

(c) i = ‘N’ or i = ‘n’ (d) i == ‘N’ and i == ‘n’

54. Which value will be assign to variable n in line 5 as marked?


(a) n − 1 (b) n + 1 (c) n (d) n * n

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.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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

It does not start with a leading forward slash. r Reading


w Writing
13. The def keyword is followed by the function
name and parenthesis. a Appending
b Binary data
14. We use the function append() to add an
element to the list. + Updating

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

list of strings. There is no return value. 35. 15 − (2 + 7 ) * 5 + 3 * *2 * 6 − 4 + 2


Syntax fileObject.writelines(sequence)
= 15 − (9 ) * 5 + 3 * *2 * 6 − 4 + 2
25. fp.size is not a valid attribute of a file object = 15 − 9 * 5 + 9 * 6 − 4 + 2
(fp). Because it has not been implemented.
= 15 − 45 + 9 * 6 − 4 + 2
26. dict is representing the dictionary. = 15 − 45 + 54 − 4 + 2
The value for key (15, 25, 35) is = 15 + 9 − 4 + 2
a + b − c = 15 + 25 − 35 = 5 = 15 + 5 + 2
The value for key (25, 20, 40) is = 20 + 2
a + b − c = 25 + 20 − 40 = 5 = 22
where, (15, 25, 35) and (25, 20, 40) are keys and 36. Changes do not happen in-place, rather a new
5 and 5 are values. instance of the string is returned.
27. if (9 > 7) true 37. A list of tuples is a list itself. Hence, items of a
if (7 > 2 and 7 > 2) true list can be sorted.
m=5−1=4 38. We use the * operator to indicate, that the
So, output is m = 4 function will accept arbitrary number of
arguments. The sum() function will return the
k=2
sum of all arguments. The first string in the
j=1 function body is called the function
28. When Fun() will be called, it display the value documentation string. It is used to document
of number is 5. the function. The string must be in triple
quotes.
After Fun(), the value of number will display 2.
39. Since ‘x’ has been declared a global variable, it
29. Variable i starts from 1 and check while
can be modified very easily within the
condition. It prints number from 1, 2, .. and so
function. Hence, the output is 3.
on, but when value of i is completely divided
by 5, then loop will be terminate. 40. Iteration 1 while (0<10) : True
So, output is 1 prints 0
i=0+2=2
2
if (0==8) : False
3 Iteration 2 while (2<10) : True
4 prints 2
30. Variable i takes the value of one word at a time. i=2+2=4
if (4==8) : False
It will print one word then comma and then
second word and so on. Iteration 3 while (4<10) : True
prints 4
31. The append function simply adds its
i=4+2=6
arguments at end to the list as it is while
extend function extends its arguments and if (6==8) : False
later appends it. Iteration 4 while (6<10): True
prints 6
32. abspath() method returns a normalised
i=6+2=8
absolutised version of the pathname path that
means returns the complete path name of the if (8==8) : True
SAMPLE PAPER 3

data file. break


So, output is 0
33. This program counts the alphabets which are
not vowels (i.e. a, e, i, o, u). So, this program 2
counts the consonants. 4
34. This code opens the file “Employee. dat” in 6
read mode and display details of employees 41. Range of for loop will start from index number
who are earning between 20000 and 40000 1 to index number 4, i.e. elements 30 to 60. So,
(both are inclusive). the value AR[K] should be between 30 and 60.

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

2. To create a dictionary in Python, ............ pair is used.


(a) key : value (b) key + value
(c) key – value (d) key = value

3. All the errors that are detected and displaced by the compiler or interpreter are
known as
SAMPLE PAPER 4

(a) run-time errors (b) compile-time errors


(c) logical errors (d) None of these

4. Which of the following is/are Python syntax error?


(a) Leaving out a keyword (b) Misspelling a keyword
(c) Incorrect indentation (d) All of these

5. The collection of functions creates a


(a) program (b) software
(c) recursion (d) library

https://t.me/cbseexamsweb
82 CBSE Sample Paper Computer Science Class XII (Term I)

6. Which of the following is/are built-in function(s)?


(a) type () (b) input () (c) print () (d) All of these

7. Which function is used to generate a sequence of numbers overtime?


(a) range() (b) len() (c) limit() (d) lim()

8. ……… statements enable a program with a cyclic flow of logic.


(a) Sequence (b) Compound
(c) Single (d) Iterative

9. What is the output of the following code?


num=4+float(7)/int(2.0)
print(num)
(a) 6.5 (b) 7.5 (c) 7 (d) 5

10. What is the minimum number of iterations that while loop could make?
(a) 1 (b) 2 (c) − 1 (d) 0

11. Identify the output of below code.


l1=list()
print(l1)
(a) [] (b) Error (c) (,) (d) ()

12. Which method is used to convert string into tuple?


(a) string() (b) convert() (c) replace() (d) tuple()

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

14. The function pow(x,y,z) is evaluated as


(a) (x**y)**z (b) (x**y) / z (c) (x**y) % z (d) (x**y)*z

15. What will be the output of the following Python function?


sum(6, 2, 7)
sum([3, 8, 6])
(a) Error, 17 (b) 15, Error (c) 15,7 (d) Error, Error

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

17. What will be the output of the following Python code?


SAMPLE PAPER 4

>>>“Welcome to Study Corner”.split()


(a) [“Welcome”,“ to”,“ Study”,“ Corner”]
(b)( “Welcome”,“ to”,“ Study“,“ Corner”)
(c) {“Welcome”,“ to”, “Study”, “Corner”}
(d) “Welcome”, “to”, “Study”, “Corner”

18. What is the data type of (1)?


(a) Tuple (b) Integer
(c) Both (a) and (b) (d) List

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 83

19. The process of pickling in Python includes


(a) conversion of a list into a datatable
(b) conversion of a byte stream into Python object hierarchy
(c) conversion of a Python object hierarchy into byte stream
(d) conversion of a datatable into a list

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

21. Which of the following expression is an example of type conversion?


(a) 2.0 + float(5) (b) 6.8 + 9.8 (c) 11.0 + 9 (d) 23 + 5

22. What will be the output of the following Python code?


print(‘@Study12#Corner!’.istitle())
(a) True (b) False (c) Error (d) None

23. What will be the output of the following code?


L1=[7, 2, 3, 4]
L2=L1+2
print(L2)
(a) [9, 4, 5, 6] (b) [7, 2, 3, 4, 2] (c) [2, 7, 2, 3, 4] (d) Error

24. Identify the for loop condition is to be repeated 100 times.


(a) for i in range (0,100) : (b) for i in range (1,100) :
(c) for i in range (0,100+1) : (d) for i in range (1,100+2) :

25. Observe the tuple and find the output.


t1=(4, 7, 8, 9)
t2=(0, 4, 3)
t=t1*t2
print(t)
(a) (4, 7, 8, 9, 0, 4, 3) (b) (0, 4, 3, 4, 7, 8, 9)
(c) (4, 7, 0, 4, 3, 8, 9) (d) Error

Section B
SAMPLE PAPER 4

This section consists of 24 questions (26 to 49). Attempt any 20 questions.

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)

(c) with open(‘test.bin’,‘wb+’)as f:


pickle.dump(f,t1)
(d) with open(‘test.bin’,‘ab’)as f:
pickle.dump(f,t1)

27. What will be the output of following code?


w=90
while (w>60):
print(w)
w=w−40
(a) 60 (b) 50 (c) 90 (d) 90
50

28. What will be the output of the following Python code?


val = [[4, 9, 6, 3], [2,6, 7,4]]
a = val[0][0]
for i in val:
for j in i:
if a> j:
a = j
print(a)
(a) 2 (b) 3 (c) 5 (d) 6

29. What will be the output of the following Python code?


def test(a):
print(a+1)
a= − 3
a=6
test(25)
(a) 26 (b)10 (c) 2 (d) 25

30. What will be the output of the following Python code?


def test(x):
x = [5]
a = [1]
test(a)
print(a)
(a) [1] (b) [5]
(c) [5, 1] (d) [1, 5]

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

(a) {‘Numbers’: {1: 6, 3: 7}, ‘Letters’: {4: ‘B’}}


(b) ‘Numbers’: {1: 6, 3: 7}
(c) {‘Numbers‘: {1:6}, ‘Letters’: {4: ‘B’}}
(d) Error, dictionary in a dictionary cannot exist

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

34. What is the result of following expression?


A=3*4//5+5//7+8−2+4//2
(a) 12 (b) 10
(c) 8 (d) 14

35. Find the output of the following code.


num=123
f=0
s=0
while(num > 3):
rem = num % 100
if(rem % 2 ! = 0):
f + = rem
else:
s + = rem
num / =100
print(f−s)
(a) 21 (b) 13 (c) 23 (d) 24

36. What will be the output of following code?


SAMPLE PAPER 4

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)

37. Consider the following code :


f = open (“mytry”,“w+”)
f.write(“0123456789abcdef”)
f.seek(−3,2) #Statement 1
print(f.read(2)) #Statement 2
Give the output of Statement 2.
(a) ab (b) bc
(c) cd (d) de

38. What will be the output of the following code?


import random
X=random.random( )
Y=random.randint(0, 4)
print(int(X), “:”, Y+int(X))
(a) 0:0 (b) 1:6 (c) 2:4 (d) 0:4

39. What is the output of following code?


def test (a, b):
x=a*b
print(x)
n1=23
n2=2
test(n1, n2)
(a) 25 (b) 23
(c) 46 (d) 23, 2

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

41. What will be the output of following code, if value of L is [2, 3, 5, 1, 7] ?


def oddtoeven(L):
for i in range(len(L)):
if(L[i]%2 !=0):
L[i] = L[i]*2
print(L)
SAMPLE PAPER 4

(a) [4, 6, 10, 2, 14] (b) [2, 6, 10, 2, 14]


(c) [2, 1, 3, 5, 7] (d) Error

42. What will be the output of the following Python code?


i = 1
while i < 5:
print(i)
i += 1
else:
print(1)

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 87

(a) 2 (b) 1 (c) 1 (d) 1


3 2 2 1
4 3 3 2
1 4 4 3
1 4

43. What will be the output of the following Python code?


a=(23, 56, 12, 62, 23)
b=slice(0,2)
print(a[b])
(a) Invalid syntax for slicing (b) [23, 12]
(c) (23, 56) (d) (23, 56, 12)

44. What will be the output of the following Python code?


def test(c):
return c * 9/5 + 32
print(test(120))
print(test(O))
(a) 248.0 (b) 256.0 (c) 32.0 (d) 32.0
32.0 64 248.0 32.0

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

46. What is the output of following code?


t1=(4,)
t2=( )
t=t1+t2
any(t)
(a) False (b) True (c) 0 (d) Error

47. Suppose the content of file ‘‘para.txt’’ is


Welcome to study corner!!

What will be the output of code?


f=open(“para.txt”, ‘r’)
a=f.read( )
print(len(a))
SAMPLE PAPER 4

f.close( )
(a) 25 (b) 23 (c) 22 (d) 26

48. Identify the error in following statements if any.


a=int(input(“Enter a:”)) # Statement 1
b=0 # Statement 2
c=a/b # Statement 3
(a) Statement 1 (b) Statement 2
(c) Statement 3 (d) None of these

https://t.me/cbseexamsweb
88 CBSE Sample Paper Computer Science Class XII (Term I)

49. What will be the output of following code?


list1=[2, 5, 4, [9, 6], 3]
list1[3][2] =10
print(list1)
(a) [2, 5, 4, [9, 10], 3] (b) [2, 5, 4, 10, [9, 6], 3] (c) Index out of range (d) None of these

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

(a) strip () (b) lstrip () (c) rstrip () (d) isdigit ()

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

55. Choose the correct condition to fill up the blank in line 6.


(a) C ! = 0 (b) C < = 0 (c) C > 0 (d) C < 0

https://t.me/cbseexamsweb
OMR SHEET SP 4
Roll No.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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.

1. Each key value pair in a dictionary is separated by a .............


(a) : (b) ; (c) – (d) =

2. Dictionaries are also called


(a) mappings (b) hashes (c) associative arrays (d) All of these

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

6. What is the output of following code?


a=10
b=2
print(a+10*2+b)
(a) 32 (b) 40 (c) 42 (d) 30

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 93

7. Identify the keyword from the following used in Python.


while, value, file, Lvalue, Rvalue
(a) value (b) file (c) while (d) Lvalue

8. User can also add elements into an empty dictionary by


(a) dictionary_name=value (b) dictionary_name[key]=value
(c) dictionary_name(key)=value (d) dictionary_name{key}=value

9. Observe the output.


c=‘7’+2
print(c)
(a) 9 (b) 72 (c) 27 (d) Error

10. Find the output of the following code.


>>>complex (4, 8)
(a) 4+8j (b) 4j+8 (c) 4j+8j (d) Error

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+

12. Which method specifies 6 characters the string should return?


(a) read(5+1) (b) readline(6) (c) readlines(6) (d) read(6)

13. To display elements from beginning to a range use


(a) [: index] (b) [index :] (c) [index : 0] (d) [: : index]

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

16. What will be the output of the following Python code?


for i in range(1, int(3.0)):
print(i)
(a) 1 (b) 0 (c) 1 (d) 0
2 1 2 1
3 2

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

18. To open a file ‘‘D:\Story.txt’’ for appending data, we use ………


(a) f = open(“D:\Story.txt”, “a”)
(b) f = open(“D:\Story.txt”, “rw”)
(c) f = open(file = “D:\Story.txt”, “w”)
(d) f = open(file = “D:\Story.txt”, “w+”)

https://t.me/cbseexamsweb
94 CBSE Sample Paper Computer Science Class XII (Term I)

19. Which of the following expressions results in an error?


(a) int(1101) (b) int(‘1101’,23)
(c) int(1101,2) (d) int(‘1101’)

20. Is the following Python code valid?


>>>tup1=(56, 25,36, 15)
>>> result=tup1.update(4,)
(a) Yes, tup1=(56, 25, 36, 15,4) and result=(56, 25, 36, 15,4)
(b) Yes, tup1=(56, 25, 36,15) and result=(56, 25, 36, 15,4)
(c) No, because tuples are immutable
(d) No, because wrong syntax for update() method

21. Which of the following is an invalid variable name?


(a) Add_num_3 (b) 1st_number (c) test (d) _num2

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

24. Find the output from the following code.


list1=[2, 5, 4, 7, 7, 7, 8, 90]
del list1[2 : 4]
print(list1)
(a) [2, 5, 7, 7, 8, 90] (b) [5, 7, 7, 7, 8, 90] (c) [2, 5, 4, 8, 90] (d) Error

25. What is the output of following code?


>>> dic={‘A’ : ‘One’, ‘B’ : ‘Two’, ‘C’ : ‘Three’}
>>>dic.keys()
(a) [‘B’, ‘C’, ‘A’] (b) dict_keys [(‘B’, ‘C’, ‘A’)]
(c) dict_keys ([‘B’, ‘C’, ‘A’]) (d) keys ([‘B’, ‘C’, ‘A’])

Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.
SAMPLE PAPER 5

26. What will be the output of following code?


l=[]
for i in range (20,40):
if (i% 7==0) and (i% 5 ! =0) :
l.append (str(i))
print(‘,’.join (l))
(a) 21 (b) 21 (c) 35 (d) Error
28 28
35

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 95

27. What is the output of following code?


def str (*a):
for i in a:
print(i)
str (* [“Hello”])
(a) Hello (b) ‘‘Hello’’ (c) ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ (d) Error

28. Identify the output of the following Python statement.


x = [[1, 2, 3, 4], [5, 6, 7, 8]]
y = x [0] [2]
print(y)
(a) 3 (b) 4 (c) 6 (d) 7

29. What is the output of following code?


def fun(Hello, n=2):
print(Hello * n)
fun(‘World’)
(a) World (b) WorldWorld (c) HelloHello (d) HelloWorld

30. What is the output of following code?


a=10
def value(i):
c=0
c=a+i
return c
value(5)
(a) 5 (b) 10 (c) 15 (d) 105

31. What is the output of following code?


str1=“ARIHANT”
final=“ ”
for i in range(len(str1)):
if(i%2==0):
final=final+str1[i]
print(final)
(a) RHNT (b) AIAT (c) ARIH (d) HANT

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

pickle. —————— # Statement 1


f.close()
Identify the missing code in Statement 1.
(a) dump(f,l1) (b) dump(l1,f) (c) write(l1,f) (d) write(f,l1)

33. What will be the output of the following Python code?


x = “123456”
i = “a”
while i in x:

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

34. What will be the output of the following Python code?


def test(): a=25
a=5
test()
a
(a) Error (b) 25 (c) Junk value (d) 5

35. What is the output of the following Python code?


a = 20
def test(a):
print(a)
a=5
test(a)
print(a)
(a) 20 (b) 20 (c) 20 (d) Error
20 5 40

36. What will be the output of the following Python code?


str1=“H#E#L#L#O”
b=list(str1.split( “#”,2))
print(b)
(a) [‘H’, ‘E’, ‘L#L#O’] (b) [‘H’, ‘E’, ‘L’, ‘L’, ‘O’]
(c) [‘H#E’, ‘L#L#O‘] (d) Error

37. What will be the output of the following Python code?


myfile = None
for i in range (4):
with open(“data.txt”, “w”) as my file
if i > 3:
break
print(myfile.closed)
(a) True (b) False (c) None (d) Error

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

39. What is the output of following code?


SAMPLE PAPER 5

def work (a=10, b=20) :


s=a+b
print(s)
return
x=23
y=62
work(x, y)
(a) 30 (b) 85 (c) 33 (d) 82

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 97

40. What will be the output of following code?


import random
X=3
N=random.randint(1, X)
for i in range(N):
print (i, ‘#’, i+1)
(a) 3#4 (b) 4#5 (c) 5#6 (d) 2#3

41. Suppose the content of file ‘‘para.txt’’ is


Welcome to study corner!
How are you students?
What are you doing now?

What will be the output of following code?


def count( ):
f=open (“para.txt”, “r”)
lines=0
l=f.readlines()
for i in l:
if i[0] ! = ‘W’ :
lines+=1
print(lines)
(a) 3 (b) 1 (c) 2 (d) Error

42. Consider the following code :


f=open(“Story”, “w+”)
f.write(“abcdefgh@#”)
f.seek(4, 3)
print(f.read(3))
What will be the correct output?
(a) def (b) cde (c) efg (d) fgh

43. What is the output of following code?


list1=[4, 3, 7, 6, 4, 9, 5, 0, 3, 2]
l1=list1[1:10:3]
print(l1)
(a) [3, 7, 6] (b) [3, 4, 0] (c) [3, 6, 9] (d) [7, 9,2]

44. What is the output of following code?


dic1={11, 12, 13}
for i in dic1:
SAMPLE PAPER 5

print(i)
(a) 11 12 13 (b) {11, 12, 13} {11, 12, 13} {11, 12, 13}
(c) Error (d) None

45. What is the output of following code?


x=15
globals() [‘x’]=63
print(x)
(a) 15 (b) 78 (c) 63 (d) Error

https://t.me/cbseexamsweb
98 CBSE Sample Paper Computer Science Class XII (Term I)

46. What will be the data type of s?


myfile=open(‘arihant’, ‘r’)
s=myfile.read()
print(s)
myfile.close()
(a) string (b) list (c) dictionary (d) tuple

47. Observe the following code:


def fun(num):
—————— # Statement 1
print(fun(25))
Choose the correct option to fill up the blank in Statement 1.
(a) return 0 (b) return 1
(c) return num (d) None of these

48. What is the output of following code?


t1=(3, 4, (6, 1), 7)
t=t1*2
print(t)
(a) (6, 8, (12, 2), 14) (b) (3, 4, (6, 1), 7, 3, 4, (6, 1), 7)
(c) (3, 4, (6, 1), (6, 1), 7) (d) Error

49. Identify the line which has an error.


i=0 # Line 1
while(i<25) # Line 2
print(“Hello”) # Line 3
i=i+1 # Line 4
(a) Line 1 (b) Line 2 (c) Line 3 (d) Line 4

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

50. Riya should open which file to search any string?


(a) school.bin (b) school.txt (c) school.bat (d) school.csv

51. Choose the correct option to fill up the blank in Line 5.


(a) f (b) found (c) datafile (d) check()

52. Which value will be assign to f in Line 7?


(a) 0 (b) 1 (c) False (d) True

53. Choose the correct option to fill up the blank in Line 8.


(a) break (b) continue (c) goto (d) label

54. Choose the correct option to fill up the blank in Line 11.
(a) 0 (b) 1 (c) False (d) True

55. Which variable or value will be print by last line?


(a) “True” (b) “False” (c) True (d) False

SAMPLE PAPER 5

https://t.me/cbseexamsweb
OMR SHEET SP 5
Roll No.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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.

1. Which of the following is/are jump statement(s)?


(a) break (b) continue
(c) Both (a) and (b) (d) None of these

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

3. Identify the output.


>>> a = ‘1234’
>>>type(a) is not str
SAMPLE PAPER 6

(a) False (b) True (c) 0 (d) − 1

4. Which method is provided by pickle module for writing in binary files ?


(a) load () (b) write () (c) seek () (d) dump ()

5. Which standard file stream is used for standard error?


(a) sys. stderr (b) sys.stdout (c) sys.stdin (d) None of these

6. Which function must use to read data from CSV files?


(a) read() (b) reader() (c) readline() (d) readlines()

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

8. This symbol is used at the end of def line.


(a) ; (b) ! (c) # (d) :

9. ……… is a variable used to define a particular value during a function definition.


(a) Argument (b) Parameter
(c) Both (a) and (b) (d) None of these

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

13. What is the role + operator in tuple?


(a) Replicate the tuple (b) Concatenate the tuple
(c) Slice the tuple (d) Traverse the tuple

14. Which variable is defined inside any function?


(a) Local variable (b) Global variable
(c) Both (a) and (b) (d) None of these

15. What is the significance of the wb+ mode?


(a) Opens a file for writing only in binary format
(b) Opens a file for reading only in binary format
(c) Opens a file for appending in binary format
(d) Opens a file for both writing and reading in binary format

16. Which of the following statement is false?


(a) Global variables are declared outside of all functions.
(b) Global variables are useful for all functions.
(c) Global variables are also called global scope.
(d) Global variables are used as global namespace.

17. What will be the output of the following Python function?


SAMPLE PAPER 6

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

20. What is the expansion of EOL?


(a) End of Line (b) Enter of Line
(c) End of Large element (d) None of these

21. Which of the following method returns a list of string?


(a) read() (b) read([size])
(c) readline() (d) readlines()

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

23. ..... exception is raised when result of an arithmetic operation is large.


(a) KeyError (b) NameError
(c) OverflowError (d) ValueError

24. Which of the following is invalid identifier?


(a) Name (b) num^2 (c) num1 (d) _SUM

25. Identify the output of following function.


range(5)
(a) [0, 1, 2, 3, 4] (b) [0, 1, 2, 3, 4, 5]
(c) [1, 2, 3, 4, 5] (d) [1, 2, 3, 4]

Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.

26. What is the output of following code?


dic={‘A’ : 5, ‘B’ : 3, ‘C’ : 2}
res=1
for key in dic :
res=res*dic[key]
print(res)
(a) 30 (b) 10 (c) 11 (d) 17

27. What will be the output of the following Python code?


a= “123456”
i=“K”
while i in a:
a=a[1:]
print(i, end =“ ”)
(a) K K K K K K (b) K
SAMPLE PAPER 6

(c) No output (d) Error

28. What will be the output of the following Python code?


def test(a) :
a =a +[3]
x= [6,9, 5, 3, 7]
test(x)
print(len(x))
(a) 4 (b) 5 (c) 1 (d) Error

https://t.me/cbseexamsweb
106 CBSE Sample Paper Computer Science Class XII (Term I)

29. What is the output of the following Python code?


def test():
return val +1
val= 0
print(test())
(a) 0 (b) 1 (c) Error (d) None

30. Suppose the content of file “story.txt” is


WONDER WORLD
Hello
Honesty

What is the output of the following Python code?


myfile=open(“story.txt”,‘r’)
for line in reversed(list(myfile)):
print(line. rstrip())
myfile.close()
(a) WORLD WONDER (b) REDNOW DLROW
Hello olleH
Honesty ytsenoH
(c) Error (d) Honesty
Hello
WONDER WORLD

31. Suppose the content of file “story.txt” is


wonder world
hello
honesty

What is the output of the following Python code?


myfile = “story.txt”
with open(myfile, ‘r’) as f:
for line in f:
l=line.title()
print(l)
f.close()
(a) Wonder World (b) Wonder world
Hello Hello
Honesty Honesty
(c) Wonder World (d) Wonder world
SAMPLE PAPER 6

hello hello
honesty honesty

32. What is the output of the following code?


def dic1(a):
for i in a :
print (i, “:”, a[i])
dic1 ({1 : “A” , 2 : “B”, 3 : “C”})

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 107

(a) 1 : A, 2 : B , 3 : C (b) 1 : “A”, 2 : “B”, 3 : “C”


(c) 1 : “A” (d) 1 : A
2 : “B” 2:B
3 : “C” 3:C

33. What is the output of following code, if List x contains 7 integers?


x=[4, 8, 7, 5, 6, 2, 10]
def test (x) :
for i in range (len(x) −1, −1, − 1):
print (x[i]*2)
(a) [20, 4, 12, 10, 14, 16, 8] (b) [8, 16, 14, 10, 12, 4, 20]
(c) [10, 2, 6, 5, 7, 8, 4] (d) Error

34. What will be the output of following code?


def test (a, b):
val = a − b
test = test (53, 40)
print(test)
(a) 13 (b) 0 (c) None (d) Error

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

36. What is the output of following code?


x=20
def output (num):
global x
x=28
if num % 5==0:
x=x+num
else:
x=x-num
print(x, end=“#”)
output (18)
print(x)
(a) 20#10 (b) 20#28
(c) 10#20# (d) 20#5

37. What will be the output of the following Python code?


i = 1
while True:
SAMPLE PAPER 6

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)

38. What is the output of following code?


def test(i, a = []):
a.append(i)
return a
test(25)
test(32)
s = test(17)
print(s)
(a) [25] [32] [17] (b) [25, 32, 17]
(c) [25] [25, 32] [25, 32, 17] (d) 25 32 17

39. What will be the output of the following Python code?


def test():
i=8
print(i)
i=15
test()
(a) Error (b) 15
(c) 8 (d) 8 15

40. What is the output of following code?


def f1():
n=44
def f2() :
n=77
print(n)
print(n)
f1()
f2()
(a) 44 (b) 77 (c) 44 (d) 77
77 77 44 44

41. What is the output of following code?


dic = {}
dic[1] = 1
dic[‘1’] = 2
dic[1.0] = 4
sum = 0
for i in dic:
sum = sum + dic[i]
print(sum)
SAMPLE PAPER 6

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

42. What is the output of following code?


t=(4,0, ‘Hello’, 90, ‘Two’, (‘One’, 45), 34, 2)
t1=t[1]+t[−2]
print(t1)
(a) 34 (b) 38
(c) Hello34 (d) 45

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 109

43. What is the output of following code?


n=5
f=1
while(n>0) :
f=f*n
n=n−1
print(f)
(a) 15 (b) 5
(c) 6 (d) 120
44. What is the output of following code?
t=(1, 2, ‘Hello’, ‘The’, 3, 4)
print(max(t))
(a) ‘Hello’ (b) 4
(c) ‘The’ (d) Error

45. What is the output of following code?


def c(x, y):
return x+y
c(3, 1.6)
(a) 3 (b) 4.6
(c) 4 (d) 1.6

46. Suppose the content of file ‘‘story. txt’’ is


Hello
Wonder
World

What is the output of the following Python code?


f=open (“story.txt”, ‘r’)
s=f.readlines()
print(s)
f.close()
(a) [‘Hello\n’, ‘Wonder\n’, ‘World’] (b) [‘Hello’, ‘Wonder’, ‘World’]
(c) [‘Hello\n’, ‘Wonder\n’, ‘World\n’] (d) [Hello\n, Wonder\n, World]

47. What will be the output of following code?


t=[“T”, “U”, “P”, “L”, “E”]
t1=tuple(t)
print(t1)
(a) (TUPLE) (b) (T, U, P, L, E)
SAMPLE PAPER 6

(c) (‘T’ ‘U’ ‘P’ ‘L’ ‘E’) (d) (‘T’, ‘U’, ‘P’, ‘L’, ‘E’)

48. Predict the output.


dic={‘a’ : 1, ‘b’ : 2, ‘c’ : 3, ‘d’ : 4}
if ‘a’ in dic :
del dic[‘a’]
print(dic)
(a) {‘b’ : 2, ‘c’ : 3, ‘d’ : 4} (b) {‘a’ : 1}
(c) None (d) Error

https://t.me/cbseexamsweb
110 CBSE Sample Paper Computer Science Class XII (Term I)

49. Suppose the content of file ‘test.txt’ is


Arihant@123#!

What will be the output of following code?


f=open(‘test.txt’, ‘r’)
a=f.read()
print(len(a))
f.close()
(a) 10 (b) 7 (c) 13 (d) 14

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

50. Choose the correct option to fill the blank in Statement 1.


(a) = = (b) > = (c) < = 0 (d) ! =

51. Which value or variable will come in function islower() in Statement 2?


(a) str1 (b) i (c) newstr (d) count

52. Choose the correct option to fill the blank in Statement 3.


SAMPLE PAPER 6

(a) (i) (b) (i+1) (c) (str1) (d) (newstr)

53. Which value will be assign to variable count in Statement 4?


(a) i (b) count −1 (c) count +1 (d) str1 +2

54. Choose the correct option to fill up the blank in Statement 5.


(a) str (b) newstr (c) count (d) i

55. Choose the correct option to fill up the blank in Statement 6.


(a) newstr + 1 (b) newstr + 2 (c) newstr (d) newstr + i

https://t.me/cbseexamsweb
OMR SHEET SP 6
Roll No.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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

e.g. def add (a, b) :


22. CSV files are used to store a large number of
print (a + b) variables or data. They are incredibly
where, a and b are parameters. simplified spreadsheets. Each line in a CSV file
10. Global namespace includes names from is a data record.
various imported modules that you are using 23. OverflowError exception is raised when result
in a project. When the module is included in of an arithmetic operation is too large to be
the project, it is created and it lasts until the represented.
script ends. 24. num^2 is invalid identifier because we cannot
11. It has a TypeError because cannot multiply use special symbols in identifiers.
sequence by non-int of type ‘str’.

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

= 2 + 26 =28 So, output is 120.

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.

1. Which of the following is invalid identifier?


(a) lambda (b) name1 (c) _SUM (d) FOR

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

(a) Relative path (b) Absolute path


(c) getcwd path (d) seek path

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)

7. What is the use of ab access mode?


(a) Opens a file for reading in binary format
(b) Opens a file for writing in binary format
(c) Opens a file for appending in binary format
(d) Opens a file for both appending and reading in binary format

8. Type of sequence data type is/are


(a) string (b) list
(c) tuple (d) All of these

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

12. Which of the following is used for standard output?


(a) sys.stdin (b) sys.stdout
(c) sys.out (d) sys.output

13. remove () method is used to ……… in Python.


(a) remove an existing file (b) remove a current file
(c) remove an exit file (d) remove a first file

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

15. What is the use of seek() method in files?


(a) Sets the file’s current position at the offset
(b) Sets the file’s previous position at the offset
SAMPLE PAPER 7

(c) Sets the file’s current position within the file


(d) None of the mentioned

16. Which of the following is not an advantage of using modules?


(a) Provides a means of reuse of program code
(b) Provides a means of dividing up tasks
(c) Provides a means of reducing the size of the program
(d) Provides a means of testing individual parts of the program

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 117

17. What will be the output of the following Python function?


min(max(False,−13,−14),12,17)
(a) 12 (b) False
(c) − 13 (d) − 14

18. How are keyword arguments specified in the function heading?


(a) One star followed by a valid identifier
(b) One underscore followed by a valid identifier
(c) Two stars followed by a valid identifier
(d) Two underscores followed by a valid identifier

19. What will be the output of the following Python code?


>>>tuple1 = (11, 12, 14, 13)
>>>tuple2 = (11, 12, 13, 14)
>>>tuple1 < tuple2
(a) True (b) False
(c) Error (d) None

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

21. Which is the correct operator for power?


(a) a^b (b) a**b
(c) a^^b (d) a*^b

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

23. Identify the arguments in following code.


def addition (a, b) :
print (a + b)
x = 5
addition(10, x)
(a) a, b (b) 10, x
(c) 5 (d) a, b , 10, x

24. Which type of data file stores the data in tabular form?
SAMPLE PAPER 7

(a) Text (b) Binary


(c) CSV (d) None of these

25. Which of the following is not included in logical errors?


(a) Using the wrong variable name
(b) Leaving out a keyword
(c) Getting operator precedence wrong
(d) Indenting a block to the wrong level

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.

26. What is the output of following code?


str1 = “Python Program”
print(str1 [3 : 7])
(a) hon (b) rog
(c) gra (d) tho

27. Suppose the content of file ‘‘para.txt’’ is


Welcome to study corner!
Hard work is the key of success.

What will be the output of the following code?


f = open (“para.txt”)
s = f.readlines( )
print(len(s))
f. close( )
(a) 2 (b) 11
(c) 4 (d) 7

28. Identify the output of following Python statement.


a = [[0, 1, 2], [3, 4, 5, 6]]
b = a [1] [2]
print (b)
(a) 2 (b) 1
(c) 4 (d) 5

29. Identify the output of following code.


a = 3
while a < 15 :
print (a , end = “ ”)
a = a + 2
(a) 3 5 7 9 11 13 15 (b) 3 5 7 9 11 13
(c) 1 3 5 7 9 11 13 15 (d) 1 3 5 7 9 11 13

30. Identify the output of following code.


list1 = [2, 3, 9, 12, 4]
list1.insert(4, 17)
list1.insert(2, 23)
print(list1 [−4])
SAMPLE PAPER 7

(a) 4 (b) 9
(c) 12 (d) 23

31. What is the output of following code?


def test (*x) :
for i in range(len(x) −1, −1, −1) :
print(x [i] + 2)
test(* [3, 4, 5, 9, 11, 2])
(a) [5, 4, 7, 11, 13, 2] (b) [3, 6, 5, 9, 11, 4]
(c) [5, 6, 7, 11, 13, 4] (d) [4, 13, 11, 7, 6, 5]

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

34. What will be the output of following code?


dic = {}
dic[(1, 2, 4)] = 8
dic[(4, 2, 1)] = 10
dic[(1, 2)] = 24
sum = 0
for i in dic :
sum = sum + dic[i]
print(sum)
(a) 40 (b) 42
(c) 34 (d) 18

35. What will be the output of the following Python code?


x = [‘pq’, ‘rs’]
for i in x:
x.append(i.upper())
print(x)
(a) [‘PQ’, ‘RS’] (b) [‘pq’, ‘rs’, ‘PQ’, ‘RS’]
(c) [‘pq’, ‘rs’] (d) None

36. What will be the output of the following Python code?


list1 = [5, 4, 9, 6, 2, 3]
for i in range(1, 6):
list1[i − 1] = list1[i]
for i in range(0, 6):
print(list1[i], end = “ ”)
SAMPLE PAPER 7

(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

37. What will be the output of the following Python code?


a=12
b=36
def test():
global b
a=21
b=33

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

38. What will be the output of the following Python code?


def test():
a=12
print(a−1)
a=+1
test()
(a) 13 (b) 12 (c) 11 (d) Error

39. What is the output of the following Python code?


def test():
add += 1
return add
add = 0
print(test())
(a) 0 (b) 1 (c) − 1 (d) Error

40. What is the output of following code?


dic = {‘Hello’ : 2 , ‘How’ : 3, ‘Who’ : 9}
out = 1
for key in dic :
out = out * dic[key]
print(out)
(a) 54 (b) 27
(c) 6 (d) 18

41. What will be the output of following code?


l = []
for i in range(10, 35):
if(i% 7 ! = 0) and (i% 5 = = 0)
l.append(str(i))
print(‘,’.join(l))
(a) 10 (b) 10 (c) 10 (d) 15
15 15 15 20
20 20 20 25
25 25 25 30
30 30
SAMPLE PAPER 7

35

42. Find the output of the folloiwng code.


def test (a = 2, b = 7) :
a = a + b
b + = 2
print (a, b)
test (b = 3, a = 8)
(a) 11 5 (b) 3 8 (c) 2 7 (d) 5 15

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 121

43. What is the output of following code?


def e( x, y, z) :
return (x > = y and x < = z)
e(2, 1, 0.8)
(a) 0 (b) 1 (c) False (d) True

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]

45. What is the output of following code?


def test():
f=open(“Data.txt”,“r”)
count=0
x=f.read()
word=x.split()
for i in word:
if(i==“my”):
count=count+1
print(count)
test()
When the content of file ‘‘Data.txt’’ is
My first book was Me and My Family.
It gave me chance to be known to the world.
(a) 3 (b) 4
(c) 16 (d) 2

46. What is the output of following code?


import random
list1 = [2, 3, 4, 5, 6, 7, 9]
L = random.randint(1, 4)
U = random.randint(3, 5)
for K in range (L, U + 1):
print(list1 [K], end = “#”)
(a) 2 # 4 # 6 # (b) 3 # 4 # 6 #
SAMPLE PAPER 7

(c) 2 # 5 # 9 # (d) 2 # 3 # 4 #

47. Suppose the content of file is


Computer is an electronic device.

What is the output of following code?


f = open (“data.txt”, ‘r’)
file1 = f.read(13)
print(file1)
f.close( )

https://t.me/cbseexamsweb
122 CBSE Sample Paper Computer Science Class XII (Term I)

(a) Computer is a (b) Computer


is
a
(c) Computer is an (d) Computer
is
an

48. What is the output of following code?


def test (a = 10, b = 20):
a + = 1
b = b − 1
return (a + b)
print(test (3), test ( ))
(a) 10 20 (b) 23 30 (c) 23 10 (d) 23 20

49. What is the output of following code?


def makenew (mystr):
newstr = “ ”
count = 0
for i in mystr:
if count % 2 ! = 0 :
newstr = newstr + str(count)
else:
if mystr.islower() :
newstr = newstr + upper(i)
else:
newstr = newstr + i
count + = 1
newstr = newstr + mystr[: 1]
print (newstr)
makenew(“sTUdeNT”)
(a) s1U3e5Ts (b) s1U3E5TS (c) S1U3E5TS (d) S1U3e5TS

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

left_pos = _____ # Statement 1


right_pos = len(str1)_____ # Statement 2
while _____ : # Statement 3
if not str1 [left_pos] = str1 [right_pos]:
_____ # Statement 4
left_pos+ = 1
_____ # Statement 5
_____ # Statement 6

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 123

Answer the below questions to execute the program successfully.


50. Choose the correct option to fill up the blank in Statement 1.
(a) −1 (b) 1
(c) 0 (d) None

51. Choose the correct option to fill up the blank in Statement 2.


(a) −1 (b) 1
(c) True (d) False

52. Choose the correct option to fill up the blank in Statement 3.


(a) right_pos<=left_pos (b) right_pos> =left_pos
(c) right_pos= =left_pos (d) right_pos! =left_pos

53. Identify the statement after if condition is True in Statement 4.


(a) return 0 (b) return False
(c) return 1 (d) return True

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.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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

Python. This loop is also known as entry control


heading.
loop, as condition is checked before entering.
19. Elements are compared one-by-one in this case.
10. Tuple is immutable which means it cannot be
change after creation. So, updation is not 20. Dictionary stores values in terms of keys and
possible with tuple. values.
t[3]=9 will give an Error. 21. In Python, power operator is a**b, i.e. 3**3=27.

https://t.me/cbseexamsweb
126 CBSE Sample Paper Computer Science Class XII (Term I)

22. If a local variable exists with the same name as = 20 + 4 − 1 + 4 − 3 + 0


the global variable that you want to access, = 24 − 1 + 4 − 3 + 0
then the global variable is shadowed. i.e. = 23 + 4 − 3 = 27 − 3 = 24
preference is given to the local variable.
34. This program will add the elements of
23. arguments are used to pass the value of a dictionary.
variable to a function when it is called.
35. The loop does not terminate as new elements
24. CSV (Comma Separated Values) format stores are being added to the list in each iteration.
the data in tabular form. It can also stores
So, there is no output.
tabular data in plain text.
This program shifts the element of list
25. Logical errors occur when the program does
backward
not give any error but still gives an incorrect
output. Leaving out a keyword is a syntax So, new list is 4 9 6 2 3 3.
error. 37. The statement “global b” allows the global
26. To access some part of a string or sub-string, value of b to be accessed and changed.
we use a method called slicing. Whereas the variable ‘a’ is local and hence the
change is not reflected outside the function.
Here, slicing will be start from index number 3
that means element is h. 38. The variable ‘a’ is a local variable. It is first
print with decrement by value 1 and then
27. readlines ( ) method will read from a file modified. Hence, the output of this code is 11.
line-by-line. This method will return a list of
strings, each separated by ‘\n’. 39. It will give an UnboundLocalError because
local variable ‘add’ referenced before
28. ‘a’ is a list that contains two sub-lists. In assignment.
a [1] [2], first sub-script represents the first
sub-list and second sub-script represents the 40. This program will multiple the value of keys in
second sub-list. dictionary. i.e. 2*3*9=54.

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.

1. Which of the following is an invalid name for identifier?


(a) abckm (b) S-num (c) Percent (d) _SUM

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]

4. To open a file d:\para.txt for reading, we use ………………


SAMPLE PAPER 8

(a) f = open(“d:\para.txt”, “r”) (b) f = open(“d:\\para.txt”, “r”)


(c) f = open(file = “d:\para.txt”, “r”) (d) f = open(file = “d:\\para.txt”, “r”)

5. Which operator is used to repeat the elements of the list?


(a) * (b) + (c) % (d) * *

6. Index of ……………… refers to 4th element.


(a) 3 (b) 4 (c) 5 (d) −4

7. What is mean of G in LEGB rule of scope resolution?


(a) Generation (b) Global (c) Generate (d) Globalisation

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

9. What is the output of following code?


str1 =“234.4”
print(“str1”)
(a) 234 (b) 235 (c) 234.4 (d) str1

10. Which of the following is false about tuple?


(a) Tuple holds a sequence of heterogeneous elements.
(b) Elements of tuple are mutable.
(c) Tuples are declared in parenthesis ().
(d) Tuples store a fixed set of elements.

11. Identify the wrong statement.


(a) print(t1 [−3]) (b) print(max (t1))
(c) print(sum (t1)) (d) t1[−2] = 40

12. What will be the output of following code?


L1 = [2, 3, 4, 5]
print(len (L1))
(a) 4 (b) 3 (c) 14 (d) 5

13. r + is used for


(a) reading and writing both (b) reading only
(c) writing only (d) reading in binary file

14. In complex number a + ib, ‘a’ represents as


(a) real part (b) imaginary part
(c) special part (d) None of these

15. Which of the following is a mutable data type?


(a) tuple (b) string
(c) list (d) None of these

16. Which of the following is used for standard input?


(a) sys.stdin (b) sys.stdout
(c) sys.stderr (d) All of these

17. ……………… function converts all lowercase letters into uppercase letters.
(a) lower ( ) (b) upper ( ) (c) isupper ( ) (d) islower ( )

18. What will be the output of Python code?


dic1 = {‘A’ : 11, ‘B’ : 2, ‘C’ : 3}
SAMPLE PAPER 8

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

22. Which of the following is not included by syntax error in Python?


(a) Leaving out a keyword (b) Incorrect indentation
(c) Empty block (d) Division by zero

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

25. What is the output of following code?


for i in range (−5, −7, −1) :
print(i + 1)
(a) −6 (b) −6
−7
(c) −7 (d) Error

Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.

26. What is the output of following code?


sum = 0
x = 4
while (x > 0) :
sum = sum + x
x = x − 1
print(sum)
(a) 4 (b) 10
(c) 7 (d) 5

27. What is the output of following code?


n = 5
i = 1
SAMPLE PAPER 8

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

(a) 0 (b) 0 (c) 0 (d) 0


1 1 1 1
1 1 2 2
2 2 3 3
3 4
5

28. What is the output of following code?


a = 6
b = 5.5
sum = a+b
print(type(sum))
(a) class < ‘float’ > (b) class = ‘float’ (c) < class ‘float’ > (d) < class > .< ‘float’ >

29. What will be the output of following code?


def myFunc (x, y) :
a = x * 2 + y − 3
print(a)
myFunc (25, 8)
(a) 50 (b) 55 (c) 175 (d) 172

30. Observe the following code :


myfile = open (“story.txt”, “a”)
______ # Statement 1
myfile.close( )
Fill in the blank in line marked as Statement 1 to write ‘‘Study’’ in the file ‘‘story.txt’’.
(a) myfile.write (Study)
(b) myfile.writeline (Study)
(c) myfile.write (“Study”)
(d) myfile = write (“Study”)

31. What is the output of following code?


def myFunc(x) :
x [2] = 45
list1 = [23, 12, 45, 72]
myFunc (list1)
print (list1)
(a) [23, 12, 45] (b) [23, 12, 72] (c) [45] (d) [23, 12, 45, 72]

32. Evaluate the following expression and identify the correct answer.
A = 5 + 6//3 + 10*3//4 + 2 + 3//4
SAMPLE PAPER 8

(a) 16 (b) 14 (c) 18 (d) 26

33. What is the output of following code?


def myFunc(x, y = 3) :
a = 1
for i in range (x) :
a = a * y
return a
print (f(4))
print (f(4, 4))

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

34. Suppose the content of file ‘‘story.txt’’ is


Python was designed by Guido Van Rossum

What will be the output of following code?


myfile = open (“story.txt”)
r = myfile.read( )
print(len (r))
myfile.close( )
(a) 40 (b) 39
(c) 33 (d) 34

35. What will be the output of following code?


dic1 = { }
dic1[1] = 3
dic1[‘1’] = 2
dic1[1] = dic1[1] +1
sum = 0
for i in dic1 :
sum = sum + dic1 [i]
print(sum)
(a) 5 (b) 3 (c) 6 (d) 7

36. What will be the output of the following Python code?


a = “123456”
i = “7”
while i in a :
print(i, end = “ ”)
(a) No output (b) 7 7 7 7 7 7 …
(c) 1 2 3 4 5 6 (d) 123456

37. What will be the output of the following Python code?


def myFunc(val):
val = [5]
a = [4]
myFunc(a)
print(a)
(a) [4] (b) [5] (c) [5, 4] (d) [4, 5]
SAMPLE PAPER 8

38. What will be the output of the following Python code?


a = 65
def myFunc():
global a
print(a)
a = 5
myFunc()
print(a)

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

39. What will be the output of the following Python code?


def myFunc(list1):
list1[0] = 56
x = [23, 14, 32, 99]
myFunc(x)
print(x)
(a) [56, 14, 32, 99] (b) [56, 23, 14, 32, 99]
(c) [23, 14, 32, 99, 56] (d) [23, 56, 14, 32, 99]

40. What will be the output of the following Python code?


def Func(a):
global a
a+=2
print(a)
Func(25)
print(“Arihant”)
(a) 27 (b) Hello
Arihant
(c) 27 (d) Error

41. Suppose the content of text file ‘‘story.txt’’ is


Python is a programming language.
It was designed by Guido Van Rossum.

What will be the data type of val?


myfile = open(“story.txt”, ‘r’)
val = myfile.read( )
myfile.close( )
(a) list (b) string
(c) tuple (d) sets

42. What is the output of the following code?


i = 0
def Func(i) :
i = i + 2
return i
Func(2)
SAMPLE PAPER 8

print(i)
(a) 3 (b) 1 (c) 0 (d) Error

43. What is the output of the following code?


tup1 = (56, 23, ‘Mathematics’, 44, 7, ‘English’, ‘Computer’, ‘Hindi’, 9)
print(tup1[2 : 4])
(a) (23, ‘Mathematics’) (b) (‘Mathematics’, 44)
(c) (‘Mathematics’, 44, 7) (d) (23, ‘Mathematics’, 44)

https://t.me/cbseexamsweb
134 CBSE Sample Paper Computer Science Class XII (Term I)

44. What will be the output of the following Python code?


a = 3
for i in range(a):
a += 2
print(a)
(a) 3 (b) 3 (c) 5 (d) 5
5 5 7 7
7 7 9 9
9 11

45. What will be the output of the following Python code?


books = [‘Hindi’, ‘English’, ‘Computer’]
if ‘put’ in books:
print(True)
else:
print(False)
(a) True (b) False
(c) None (d) Error

46. What will be the output of the following Python code?


x = (‘Computer’,)
n = 1
for i in range(int(n)):
x = (x,)
print(x)
(a) Error, tuples are immutable (b) ((‘Computer’,),)
(c) ((‘Computer’,)’Computer’,) (d) ((‘Computer’,)’ Computer’,)
(((‘ Computer’,)’ Computer’,)’ Computer’,)

47. What will be the output of the following Python code?


for i in range(8):
if i == 4:
break
else:
print(i)
else:
print(“Terminate”)
(a) 0 (b) 1
1 2
2 3
3
SAMPLE PAPER 8

(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

48. What is the output of the following code?


def func(a = 10, b = 10):
return(a+b, a−b)
a, b = func(b = 20, a = 10)
print(a, b)
(a) 30 -10 (b) 20 0 (c) 0 10 (d) 20 10

49. What is the output of the following code?


count = 1
def func():
global count
for i in (1, 2, 3, 4):
count += 1
func()
print(count)
(a) 4 (b) 5 (c) 6 (d) 3

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

52. Which value will be added to str1 in Statement 3?


SAMPLE PAPER 8

(a) 0 (b) 1 (c) i (d) i + 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.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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.

1. What is the maximum length of an identifier?


(a) 56 (b) 256 (c) 128 (d) Any length

2. Which of the following is not a bitwise operator?


(a) & (b) ^ (c) ! (d) /

3. What is the output of following code?


a=3+float(8)/int(3.0)
print(a)
(a) 2.66 (b) 5.66 (c) 3.66 (d) Error

4. What is the output of following code?


SAMPLE PAPER 9

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)

6. Which of the following code does not contain any error?


(a) round() (b) round (53.7)
(c) round (53.7345, 3, 2) (d) round (3454.2, 1, 1)

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 141

7. Correct syntax of readlines () is


(a) file.readlines() (b) file.readlines[]
(c) file.readlines(n) (d) readlines(file)

8. Which function is used to read single line from file?


(a) readline() (b) readlines()
(c) readstatement() (d) readfullline()

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.

11. What will be the output of the following Python function?


all(0, 6, 3.2)
(a) True (b) False (c) Error (d) 0

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

15. What is the output?


Num=2+3−1*3
(a) 12 (b) 2 (c) 4 (d) 3

16. Choose the correct for loop statement to be repeated 50 times.


(a) for in range(50): (b) for i in range(50):
(c) for i in range(0,50,1) : (d) for i in range (1,50,1) :

17. In ………, we put values together into a new tuple.


(a) unpacking (b) packing (c) replication (d) slicing
SAMPLE PAPER 9

18. If str1=“Python Program”, then what is the output of print(str1[2:12:3])?


(a) thon (b) toPr (c) tnrr (d) trrm

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)

21. What is the output?


val=‘8’+2
print(val)
(a) 82 (b) 88 (c) 22 (d) Error

22. Which of the following is a logical error?


(a) Leaving out a keyword
(b) Division by zero
(c) Using the wrong variable name
(d) Incorrect indentation

23. What will be the output of following code?


a, b =12, 10
c=a//b+4*2
d=c−10
print(d)
(a) 1 (b) − 1 (c) 0 (d) 2

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

25. What will be the output?


list1=[2, 5, 4, 7, 9, 8]
list2=list1+10
print(list2)
(a) [2, 5, 4, 7, 9, 8, 10] (b) [10, 2, 5, 4, 7, 9, 8]
(c) [2, 5, 4, 10, 7, 9, 8] (d) Error

Section B
This section consists of 24 questions (26 to 49). Attempt any 20 questions.

26. What is the output of following code?


tup1=(3, 2, 5, 9)
tup2=(3, 8, 7)
t=tup1*tup2
print(t)
(a) (3, 2, 5, 9, 3, 8, 7) (b) (3, 8, 7, 3, 2, 5, 9) (c) (3, 2, 3, 8, 7, 5, 9) (d) Error

27. What will be the output of following code?


def Func(x):
SAMPLE PAPER 9

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

29. What is the output of following code?


a = 5
def MyFunc() :
global a
a = a + 3
MyFunc()
print(a)
(a) 3 (b) 8
(c) 5 (d) Error

30. What is the output of the following code?


a = 70
while(a>50):
print(a)
a = a − 30
(a) 40 (b) 30 (c) 50 (d) 70

31. Suppose the content of file “story.txt” is


Honesty is the best policy.
What is the output of following code?
myfile=open (“story.txt”, ‘r’)
s=myfile.read(12)
print(s)
myfile.close()
(a) Honesty is (b) Honesty is the
(c) Honesty is t (d) Error

32. What will be the output of the following Python code?


a=(i for i in range(5))
for i in a:
print(i)
for i in a:
print(i)
(a) 0 (b) 1 (c) 2 (d) 1
1 2 3 2
2 3 4 3
3 4 5 4
4 5
6
SAMPLE PAPER 9

33. What will be the output of the following Python code?


def myFunc(a):
a=[‘123’, ‘abc’]
return id(a)
val=[‘abc’,‘123’]
print(id(val)= = myFunc(val))
(a) True (b) False
(c) Flag (d) Error

https://t.me/cbseexamsweb
144 CBSE Sample Paper Computer Science Class XII (Term I)

34. What is the output of the following Python code?


val=10
def test(a=2, b=val):
print(a,b)
val=23
test(5)
(a) 5 10 (b) 10 5 (c) 23 5 (d) 23 15

35. What will be the output of the following Python code?


def myFunc(a, b):
if a > b :
return a
elif a = = b:
return ‘Equal numbers’
else:
return b
print(myFunc(2, 8))
(a) 8 (b) 2 (c) Equal numbers (d) Error

36. What is the output of the following Python code?


def test(i=3, j=5):
i = i + j
j = j + 1
print(i, j)
test(j = 4, i = 5)
(a) 3 5 (b) 8 8 (c) 5 4 (d) 9 5

37. What will be the output of the following Python code?


val=12345
for i in val :
print(i)
(a) 1 2 3 4 5 (b) 12345
(c) 1 3 5 (d) Error

38. What is the output of following code?


a={11 : “Hindi”, 12 : “English”, 13 : “Science”}
for i, j in a:
print(i, j)
(a) 11 12 13 (b) Hindi English Science
(c) 11 Hindi 12 English 13 Science (d) Error

39. Consider a tuple tup1=(3, 7, 9, 6, 2) on a binary file ‘‘story.bin’’:


SAMPLE PAPER 9

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

40. Suppose the content of file “IMP.TXT” is


Pinaky has gone to his friend’s house.
His friend’s name is Ravya. Her house is 12 km from Pinaky’s house.

What is the output of following code?


def test():
f=open(“IMP.TXT”)
e=0
u=0
while True:
l=f.readline()
if not l:
break
for i in l:
if(i==‘E’ or i==‘e’):
e=e+1
elif(i==‘U’ or i==‘u’):
u=u+1
print(e)
print(u)
f.close()
(a) 5 (b) 7
3 3
(c) 3 (d) 5
3 5

41. What is the output of following code?


import random
X = [100, 75, 10, 125]
Go = random.randint (0, 3)
for i in range (Go):
print (X[i], “$$”)
(a) 100$$75$$10$$ (b) 75$$10$$125$$
(c) 75$$10$$ (d) 10$$125$$100

42. What is the output of following code?


def Findoutput ():
L = “earn”
X = “ ”
L1 = []
count = 1
SAMPLE PAPER 9

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

43. What is the output of following code?


l1=[1, 2, 8, 9, 5]
for i in range (1, 5):
l1[i−1] = l1[i]
for i in range(0, 5):
print(l1[i], end=“”)
(a) 5 5 1 2 8 (b) 5 1 2 8 9
(c) 2 8 9 5 1 (d) 2 8 9 5 5

44. What is the output of following code?


def Func():
i=11
while i>1:
if(i%2==0) :
a=i%2
i=i-1
else:
i=i−3
a=i
print(a**3)
(a) 512 (b) 512 (c) 512 (d) Error
64 64 64
64 8 64
8 0 8
0

45. Suppose the content of file ‘‘story.txt’’ is


The test of my life

What is the output of following code?


f=open(“story.txt”)
i=f.read()
print(len(i))
f.close()
SAMPLE PAPER 9

(a) 20 (b) 19 (c) 15 (d) 21

46. Suppose the content of file ‘‘exam.txt’’ is


Positive attitude is the key to solve many of the
problem which you face in your life.

What is the output of following code?


myfile=open(“exam.txt”, “r”)
i=myfile.read()
j=i.count(‘the’)

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

47. What is the output of following code?


list1=[‘PQR’, ‘XYZ’]
for i in list1:
i.lower()
print(list1)
(a) [‘pqr’, ‘xyz’] (b) [‘PQR’, ‘XYZ’] (c) [None, None] (d) Error

48. Identify the output of following code.


list1=[23, 45, 47, 72, 69]
L=list1.pop(72)
print(L)
(a) 72 (b) [23, 45, 47, 69] (c) None (d) Error

49. What is the output of following code?


i = 2
j = 5
value = 5 + 4 * 2 + i * *j
print(value)
(a) 45 (b) 23 (c) 50 (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.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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

Syntax os.remove (filename)


11. The function all() returns ‘True’ if any one or
more of the elements of the iterable are 21. It will give TypeError because integer and
non-zero. In the given case, the values are not string cannot be concatenate.
iterable, hence an error is thrown. 22. Logical errors occur when the program does
12. Zero or more keyword arguments can be not give any error but still gives an incorrect
passed to a function in a single function call. output. These errors occur due to mistakes of
the programmer.
Zero keyword arguments may be passed if all
Using the wrong variable name is an example
the arguments have default values. of logical error.

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.

= 36 + 10 = 46 43. The elements having indexes number from 1 to


4 are shifted forward by one index due to the
29. Since ‘a’ has been declared a global variable, first for loop and the item of index four is
it can be modified very easily within the printed again because of the second for loop.
function.
44. Iteration 1 while (11 > 1) : true
30. Iteration 1 while(70 > 50) : True
if (11%2 = = 0) false
prints 70
a = 70 − 30 = 40 else
Iteration 2 while (40 > 50): False i = 11 − 3 = 8
a = 8
So, output is 70.
prints 512
31. read() returns a string containing all
characters in a file. Iteration 2 while (8 > 1) : true
Syntax fileHandle.read() if (8 % 2 = = 0) true
a = 8% 2 = 4
32. We can loop over a generator object only i= 8 − 1 = 7
once. prints 64
33. A new object is created in the function. Iteration 3 while (7 > 1) : true
if (7%2 = = 0) false
SAMPLE PAPER 9

34. At the time of leader processing, the value of


‘val’ is 10. It is not modified later. The value else
passed to the function test is 5. Hence, the i=7 − 3 = 4
output of the code is 5 10. a = 4
35. The function returns the maximum of the prints 64
parameters, in this case the numbers supplied Iteration 4 while (4 > 1 ) : true
to the function. It uses a simple if..else if (4% 2 = = 0) true
statement to find the greater value and then a = 4%2 = 2
i= 4 − 1 = 3
returns that value.
prints 8

https://t.me/cbseexamsweb
152 CBSE Sample Paper Computer Science Class XII (Term I)

Iteration 5 while (3 > 1): true 49. value = 5 + 4 * 2 + 2 * * 5


if (3%2 = = 0) false = 5 + 4 * 2 + 32
else = 5 + 8 + 32
i= 3− 3 = 0 = 13 + 32
a = 0 = 45
prints 0 50. os module provides a unified interface to a
So, output is number of operating system methods.
512 51. r mode opens a file for reading only. The
64 file pointer is placed at the beginning of
64 the file.
8 52. readline() will read from file line-by-line.
0 For readline(), a line is terminated by ‘\n’
45. File ‘story.txt’ will be open in read mode by default or end of line.
and variable i store the content of file 53. When if condition becomes true it will
character-by-character. len() method is used to find pass the value.
the length or number of bytes. 54. write() takes a string and writes it into the
46. This code opens a file “exam. txt” and read the data file. This method does not add a new line
and count the ‘the’ word with count() and assigned character ‘\n’ to the end of the string.
its value to j. 55. nfile is a file object and nfile.close() is used
47. The function lower() does not modify a string in to close the file ‘algo.txt’.
place, it returns a new string which is not being It is important to close the file as soon as
stored anywhere. you have finished your work with it.
48. In pop(), parenthesis put index number instead of Opened file is closed by calling the close()
element. But in given list, maximum index number method of its file objects.
is 4 then, 72 is out of index range.
SAMPLE PAPER 9

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?

(a) (b) (c) (d)

3. Which of the following is a valid identifier?


(a) import (b) Sum^2
(c) Num123 (d) Sum Func
4. Observe the below code and find the output from the following options.
SAMPLE PAPER 10

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)

6. What is the output of following code?


>>>t=(45, 89, 9, ‘The’, 23, 25)
>>>t.index(‘The’)
(a) 3 (b) 4 (c) − 4 (d) − 2
7. Which of the following method will force out any unsaved data that exists in a
program buffer to the actual file?
(a) dump() (b) load()
(c) seek() (d) flush()
8. Which mode is used for appending in binary file?
(a) a+ (b) a
(c) ab+ (d) aw+
9. Ansh intends to position the file pointer to the end of a text file. Identify the Python
statement for the same assuming F is the Fileobject.
(a) F.tell(2) (b) F.seek(0)
(c) F.seek(1) (d) F.seek(2)
10. File extension to save the CSV file is
(a) .c (b) .csv (c) .cv (d) .cs
11. Which type of variable can be accessed only by the statements of that function?
(a) Local variable (b) Global variable
(c) Mapping variable (d) Function variable
12. What is the output of following code?
dic1={“One” : 45, “Two” : 72}
print(list(dic1.keys()))
(a) [“One” : 45, “Two” : 72] (b) [“One”, “Two”]
(c) (“One”; “Two”) (d) (“One” : 45, “Two” : 72)
13. What will be the output?
a=int(53.46 + 3/3)
print(a)
(a) 53 (b) 54 (c) 54.46 (d) 53.47
14. Which of the following is/are standard file stream(s) used in Python’s file handling?
(a) sys.stdin (b) sys.stdout
(c) sys.stderr (d) All of these
15. Observe the following code :
def Total(a,b):
print (a+b)
SAMPLE PAPER 10

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

17. Which of the following is the truncation division operator?


(a) / (b)% (c) // (d) |
18. What happens, if a local variable exists with the same name as the global variable you
want to access?
(a) The local variable is shadowed (b) Undefined behavior
(c) The global variable is shadowed (d) Error
19. Which of the following is false about “from-import” form of import?
(a) The syntax is: from modulename import identifier
(b) This form of import prevents name clash
(c) The namespace of imported module becomes part of importing module
(d) The identifiers in module are accessed directly as: identifier
20. To read the remaining lines of the file from a file object infile, we use ………… .
(a) infile.read(n) (b) infile.read()
(c) infile.readline() (d) infile.readlines()
21. Which of the following function can accept more than one positional argument?
(a) pickle.dumps() (b) pickle. loads()
(c) pickle.dump() (d) pickle. load()
22. Which statement correctly represent the Statement 1 in the given code?
def myFun(val):
______ # Statement 1
print(myFun(82))
(a) True (b) False (c) return val (d) return Flag
23. In file handling, which path does not start with a leading forward slash?
(a) Absolute path (b) Relative path
(c) Random path (d) Module path
24. Which of the following example shows the run-time error in Python programming?
(a) Incorrect indentation which does not exist
(b) Trying to access a file
(c) Using the wrong variable names
(d) Misspelling a keyword
25. ……… can be defined as an abnormal condition in a program resulting in the
disruption to the flow of the program.
(a) Exception (b) Error (c) Compile (d) Debugging

Section B
SAMPLE PAPER 10

This section consists of 24 questions (26 to 49). Attempt any 20 questions.


26. What is the output of following code?
i=1
while (i<10):
if (i= = 5):
break
print(i)
i = i + 1

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

27. What is the output of following code?


for i in range (− 6, − 10, − 2) :
print (i + 1)
(a) [ − 6, − 8] (b) [ − 6, − 4] (c) [ − 4, − 6] (d) None
28. What is the output of following code?
d={‘P’ : 12, ‘Q’ : 10, ‘R’ : 5, ‘S’ : 13}
if ‘R’ in d :
del d[‘R’]
print(d)
(a) {‘P’ : 12, ‘Q’ : 10, ‘S’ : 13} (b) [‘P’ : 12, ‘Q’ : 10, ‘S’ : 13]
(c) {‘R’ : 5} (d) [‘R’ : 5]
29. Observe the code and choose the correct option to fill up the blank marked as
Statement 1 to write ‘Learning’.
myfile=open(“Exam.txt”, ‘a’)
______ # Statement 1
myfile.close()
(a) myfile.write() (b) myfile.write (Learning)
(c) myfile.write (“Learning”) (d) writelines(“Learning”)
30. What is the output of following code?
i=4
def myFunc():
i=2
global i
i=i+2
print(i)
print(i)
(a) 6 (b) 4 (c) 6 (d) 4
2 2 4 6
SAMPLE PAPER 10

31. What will be the output of following code?


import random
arr=[2, 3, 4, 5, 6, 7]
min=random.randint(1, 3)
max=random.randint(2, 4)
for i in range(min, max+1):
print(arr[i], end=“*”)
(a) 1*4*7* (b) 3*4*5* (c) 5*6*7* (d) 4*5*7*

https://t.me/cbseexamsweb
CBSE Sample Paper Computer Science Class XII (Term I) 157

32. What will be the output of the following Python code?


i = 1
while i < 10:
print(i)
i += 3
else:
print(2)
(a) 1 (b) 1 (c) 1 (d) 1
4 4 4 4
7 7 7 7
2 10 10
2
33. What will be the output of the following Python code?
val = (i for i in range(5))
for i in val:
print(i+1)
for i in val:
print(i)
(a) 1 (b) 1 (c) 0 (d) 0
2 2 1 1
3 3 2 2
4 4 3 3
5 4 4
5
34. What is the output of the following Python code?
list1 = [23, 25, 12, 36, 22]
i = −3
for i not in list1:
print(i)
i += 1
(a) 36 22 (b) 0 (c) −3 −2 (d) Error
35. Evaluate the following expression and identify the correct answer.
A = 10 * 5 + 3 / / 4 + 12 − 8 / /3 + 2 − 1
(a) 61 (b) 62 (c) 63 (d) 64
36. What is the output of following code?
d={ }
a, b, c = 1, 2, 3
d[a, b, c] = a + b − c
a, b, c = 2, 10, 4
d[a, b, c] = a + b − c
SAMPLE PAPER 10

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)

(a) 9 (b) 12 (c) 15 (d) Error


15 15 21
21 18 21
27 21
24
27
30
38. What is the output of following code?
d={}
d[1]=5
d[‘1’]=4
d[1.0]=14
add=0
for i in d:
add=add+d[i]
print(add)
(a) 15 (b) 18 (c) 24 (d) 19
39. What is the output of following code?
tup1=(14,)
tup2=()
t=tup1+tup2
any(t)
(a) 0 (b) 1 (c) False (d) True
40. What is the output of following code?
def Func(*str1):
for i in str1:
print(i)
Func(*[“LEARN”])
(a) L, E, A, R, N (b) [L, E, A, R, N]
(c) [LEARN] (d) LEARN
41. What is the output of following code?
def test(Learn, n=1)
print(Learn*n)
test(‘Education’)
test(‘Skills’, 2)
(a) Education (b) Education (c) EducationEducation (d) EducationEducation
SkillsSkills Skills Skills SkillsSkills
42. If list val contains
SAMPLE PAPER 10

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

43. What is the output of following code?


val=7
def test():
val=2
global val
val=val+3
print(val)
print(val)
(a) 10 (b) 7 (c) 5 (d) 7
2 2 7 5
44. What is the output of following code?
def myFunc():
n=24
def myFunc1():
n=45
print(n)
print(n)
myFunc()
myFunc1()
(a) 24 (b) 45 (c) 45 (d) 24
45 24 45 24
45. When list1 is [2, 4, 5, 15, 12], then what is the output of following code?
def Func(list1) :
for i in range (len(list1)):
if(list1[i]%3!=0):
list1[i]=list1[i]*5
print(list1)
(a) [10,20, 25, 75, 60] (b) [2, 4, 5, 75, 60] (c) [10, 20, 25, 15, 12] (d) Error
46. Suppose the content of file “learn.txt” is

Education hub is study point.


Find the output.
f=open(“learn.txt”, ‘r’)
s=f.read(11)
print(s)
f.close()
(a) Education h (b) Education hu (c) Education hub (d) Education
47. Suppose the content of file “exam.txt” is

Education hub is study point where students gain their knowledge.


SAMPLE PAPER 10

What is the output of following code?


f=open(“exam.txt”, ‘r’)
s=f.read(10)
print(s)
s1=f.read(15)
print(s1)
f.close()
(a) Education (b) Education (c) Education hub is study p (d) Error
hub is study p hub is study po

https://t.me/cbseexamsweb
160 CBSE Sample Paper Computer Science Class XII (Term I)

48. Suppose the content of file ‘‘learn.txt’’ is

Education hub is study point.


What is the output of following code?
myfile=open(“learn.txt”, ‘r’)
s=myfile.read()
l1=len(s)
print(l1)
myfile.close()
(a) 29 (b) 28 (c) 24 (d) 25
49. What is the output of following code?
list1=[2, 3, [3, 5], 4]
list1[2][0]=5.4
print(list1)
(a) [2, 3, [3, 5.4], 4] (b) [2, 3, [5.4, 5], 4] (c) [2, 3, [5.4, 3, 5], 4] (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 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.

Student Name Sub Code.

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

Check Your Performance


Total Questions: Total Correct Questions
Score Percentage = × 100
Total Correct Questions: Total Questions

Less than 60% > Average (Revise the concepts again)


If Your Score is Greater than 60% but less than 75% > Good (Do more practice)
Above 75% > Excellent (Keep it on)

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

9. seek() can be used to change the current


possible in a file. If mode is set to 0, it means the local variable that you want to access, then
use the beginning of the file as the reference the global variable is shadowed. i.e. preference
position, 1 means use the current position of is given to the local variable.
file and 2 means use end of file would be taken 19. In the “from-import” form of import, there
as the reference position. may be name clashes because names of the
10. CSV (Comma Separated Values) format is a imported identifiers are not specified along
way to store data in tabular form. To represent with the module name.
a CSV file,it must be saved with the .csv file So, ‘This form of import prevents name clash’
extension. is false about from-import.

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

29. ‘‘Exam.txt’’ is a text file on which we need to


their respective keys.
write “Learning”. write () takes a string and
writes it into the given file. For key (1, 2, 3), value is ( 1 + 2 − 3) = 0 and for
key (2 , 10 , 4 ), the value is (2 + 10 − 4 ) = 8.
30. In given code, the statement succeeding the
statement global i informs Python to increment 37. This program finds all such numbers which are
the global variable i. divisible by 3 but are not a multiple of 2
between 10 and 30 (both included).
Hence, the output is 6. i.e. 4+2, which is also
the value for global i. When i is reassigned 38. d is a dictionary in which first element is 5
with the value 2 the local i hides the global i with key 1. The value of key [1] is replaced
and hence 2 is printed. with 4, second element is 14 with key [1.0] and

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

You might also like