Xii Python
Xii Python
2021 EXAM
CBSE
CLASS 12
2 SAMPLE PAPERS
SET OF
COMPUTER SCIENCE
Maximum Marks: 70
Time Allowed: 3 hours
General Instructions:
1. This question paper contains two parts A and B. Each part is compulsory.
2. Both Part A and Part B have choices.
3. Part-A has 2 sections:
a. Section – I is short answer questions, to be answered in one word or one line.
b. Section – II has two case study questions. Each case study has 4 case-based subparts.
An examinee is to attempt any 4 out of the 5 subparts.
4. Part - B is the Descriptive Paper.
5. Part- B has three sections
a. Section-I is short answer questions of 2 marks each in which two questions have
internal options.
b. Section-II is long answer questions of 3 marks each in which two questions have
internal options.
c. Section-III is very long answer questions of 5 marks each in which one question has
an internal option.
6. All programming questions are to be answered using Python Language only
Part-A
(Section-I)
a. My Work
b. mywork
c. myWORK
d. MY Work
4. What is the output of sys.platform [:2] if the code runs on windows operating system?
a. 'wi'
b. Error
c. 'op'
d. 'sy'
5. To open a file c:\res.txt for reading, we can use (select all correct options):
a. d, e, f
b. a, e, f
c. b, d, f
d. b, c, f
6. How can we find the names that are defined inside the current module?
11. When would you go for linear search in an array and when for binary search?
12. Write a query to display the Sum, Average, Highest and Lowest salary of the
employees.
a. Dept
b. ID
c. Total credits
d. Name
15. Identify the Domain name and URL from the following:
http://www.income.in/home.aboutus.htm
16. SQL applies conditions on the groups through ________ clause after groups have been
formed.
a. Where
b. Group by
c. Having
d. With
a. 0000
b. 1111
c. 1110
d. 0111
22. Give output for following SQL queries as per given table(s):
Table: GRADUATE
23. If the file 'poemBTH.txt' contains the following poem (by Paramhans Yoganand):
God made the Earth;
Man-made confining countries
And their fancy-frozen boundaries.
But with unfound boundless Love
I behold the borderland of my India
Expanding into the World.
Hail, mother of religions, Lotus, scenic beauty and sages!
What outputs will be produced by both the code fragments given below:
24. Write a program that rotates the elements of a list so that the element at the first
index moves to the second index, the element in the second index moves to the third
index, etc., and the element in the last index moves to the first index.
OR
i. FM
ii. AM
iii. NFS
iv. FTP
OR
28. Write a program that reads an integer N from the keyboard computes and displays
the sum of the numbers from N to (2 * N) if N is nonnegative. If N is a negative
number, then it's the sum of the numbers from (2 * N) to N. The starting and ending
points are included in the sum.
31. What are data types? What are the main objectives of datatypes?
33. Find the errors in following code and write the correct code.
if v < 5:
for j in range(v):
print "ABC"
else:
print "XYZ"
34. Create file phonebook.dat that stores the details in following format:
Name Phone
Jivin 86666000
Kriti 1010101
Obtain the details from the user.
35. Write a function which takes two string arguments and returns the string comparison
result of the two passed strings.
OR
Write a program that reads a date as an integer in the format MMDDYYYY. The
program will call a function that prints print out the date in the format <Month
Name><day>, <year>.
Sample run :
Enter date: 12252019
December 25, 2019
37. From the program code given below, identify the parts mentioned below :
1. def processNumber(x):
2. x = 72
3. return x + 3
4.
5. y = 54
6. res = processNumber(y)
Identify these parts: function header, function call, arguments, parameters, function
body, main program.
Section-III
38. Uplifting Skills Hub India is a knowledge and skill community which has an aim to
uplift the standard of knowledge and skills in society. It is planning to set up its
training centres in multiple towns and villages pan India with its head offices in the
nearest cities. They have created a model of their network with a city, a town, and 3
villages as follows.
As a network consultant, you have to suggest the best network related solutions for
their issues/ problems raised in (i) to (iv) keeping in mind the distance between
various locations and given parameters.
The shortest distance between various location:
VILLAGE 1 to B_TOWN 2 KM
B_TOWN 120
VILLAGE 1 15
VILLAGE 2 10
VILLAGE 3 15
Note:
In Villages, there are community centers, in which one room has been given as a
training center for this organization to install computers.
The organization has got financial support from the government and top IT
companies.
i. Suggest the most appropriate location of the SERVER in the B_HUB (out of the 4
locations), to get the best and effective connectivity. Justify your answer.
ii. Suggest the best-wired medium and draw the cable layout (location to location) to
efficiently connect various locations within the B_HUB.
iii. Which hardware device will you suggest to connect all the computers within each
location of B_HUB?
iv. Which service/protocol will be most helpful to conduct live interactions of Experts
from Head Office and people at all locations of B_HUB?
39. Consider the following tables STORE and SUPPLIERS and answer (a) and (b) parts of
this question:
Table: STORE
Table: SUPPLIERS
Scode Sname
21 Premium Stationers
23 Soft Plastics
22 Tetra Supply
40. Write a program to perform insert and delete operations on a Queue containing
Members details as given in the following definition of itemnode :
MemberNo integer
MemberName String
Age integer
OR
Solution
3. The rmdir() method deletes an empty directory, which is passed as an argument in the
method. Before removing a directory, all the contents in it should be deleted, i.e.
directory should be empty. OSError will be raised if the specified path is not an empty
directory.
4. (a) 'wi'
Explanation: windows[:2] = 'wi'
5. (d) b, c, f
Explanation:
In file path, '\r' is a carriage return character, to normalise it we use another /
before it or use 'r' prefix before the file path.
We do not need to mention the file keyword to input the file path in open
function.
6. The names defined inside a current module can be found by using dir () function.
9. 0 a 1 b 2 c
10. The variables that are defined outside every function(local scope) in the program
have a global scope. They can be accessed in the whole program anywhere (including
inside functions).
11. When the array is unsorted liner search is used Binary search is performed in a
sorted array.
12. mysql > SELECT SUM (sal), AVG (sal), MAX (sal), MIN (sal) FROM empl;
13. These are data structures whose elements form a sequence e.g. Stack, queue and
linked lists.
14. (b) ID
Explanation: ID, A primary key is a key that is unique for each record.
17. A Database connection is a facility that allows client software to talk to database
server software, whether on the same machine or not.
18. The wildcard character is used to substitute one or more characters in a string.
They are used with the LIKE operator to search a value similar to a specific pattern in
a column. There are 2 wildcard operators.
% - represents 0,1 or many characters
— represents a single number or character.
19. A repeater is an electronic device that receives a signal, amplifies it and then
retransmits it on the network so that the signal can cover longer distances.
20. MySQLdb is an interface for connecting to a MySQL database server from Python. It
implements the Python Database API v2.0 and is built on top of the MySQL API.
OR
26. An Internet Protocol (IP) address is a numerical identification and logical address that
is assigned to devices connected in a computer network. An IP address is used to
uniquely identify devices on the internet and so one can quickly know the location of
the system in the network.
In a network, every machine can be identified by a unique IP address associated with
it and thus help in providing network security to every system connected in a
network.
27. Fruitful function - The functions that return a value i.e., non-void functions are also
known as fruitful functions.
Non - fruitful function - The functions that do not return a value, i.e., void functions
are also known as non-fruitful functions.
OR
Since, a was declared after its use in myfunc() function a = 2 is declared, after the
statement y = a, resulting in the not defined error.
29. All variables in a program may not be accessible at all locations in that program. This
depends on the location of the declaration of the variable. The scope of a variable
determines the region of the program where you can access a particular identifier. If
a variable is accessed outside the scope, Python gives an error of "variable_name is
not defined".
There are two basic scopes of variables in Python :
i. Global variables that are accessible throughout the program anywhere inside all
functions have global scope.
ii. Local variables that are accessible only inside the function where they are
declared, have local scope.
31. Data types are the classification of data items. Data types represent a kind of value
which determines what operations can be performed on that data. Some common
data types are Integer, Float, Varchar, Char, String, etc.
Main objectives of datatypes are:
32. Degree. The number of columns or attributes or fields in a relation/table is called the
table's degree.
Cardinality. The number of rows/tuples/record in a relation/table is called the table's
cardinality. For example, for a table shown below :
BookNo. Name Author Price
Section- II
34. This program is used to create a file and store the data in that file:
OR
36. A module in python is a .py file that defines one or more function/classes which you
intend to reuse in different codes of your program. To reuse the functions of a given
module, we simply need to import the module using the import command.
A Python package is a collection of python modules under a common namespace
created by placing different modules on a directory along with some special files. This
feature comes in handy for organizing modules of one type in one place.
37.
Arguments y in line 6
Parameters x in line 1
x = 72
Function body in lines 2 and 3
return x + 3
y = 54
Main program in lines 5 and 6
res = processNumber(y)
Section-III
38. i. B-TOWN can house the server as it has the maximum no. of computers.
ii. The optical fiber cable is the best for this star topology.
iii. Switch device - connecting all the computers within each location of B_HUB
iv. VoIP- Voice Over Internet Protocol
39. a. i. SELECT * FROM STORE ORDER BY LastBuy;
ii. SELECT ItemNo, Item FROM STORE WHERE Rate > 15;
iii. SELECT * FROM STORE WHERE (Scode = 22 OR Qty > 110);
iv. SELECT Sname, MIN(Rate) FROM STORE, SUPPLIERS WHERE STORE. Scode =
SUPPLIERS.Scode GROUP BY Snam
b. i. 3
ii. 880
iii.
Item Sname
iv. 24-Feb-10
def Dequeue(Qu) :
if isEmpty(Qu) :
return "Underflow"
else :
item = Qu.pop(0)
if len(Qu) == 0 : # if it was single-element queue
front = rear = None
return item
def Display(Qu) :
if isEmpty(Qu) :
print ("Queue Empty!")
elif len(Qu) == 1:
print(Qu[0], "<== front, rear")
else :
front = 0
rear = len(Qu) - 1
print(Qu[front], "<-front")
for a in range(l, rear ) :
print(Qu[a])
print(Qu[rear], "<-rear")
# __main__
queue = [ ] # initially queue is empty
front = None
while True :
cls()
print("QUEUE OPERATIONS BY USING LIST")
print("l. Insert")
print("2. Delete")
print("3. Display ")
print("4. Exit")
ch = int(input("Enter your choice (1-5) : ”))
if ch == 1 :
print ("For the new member, enter details below:")
memberNo = int( input ("Enter member no :"))
memberName = input ("Enter member name :")
age = int(input("Enter memberJs age : “))
item = [memberNo, memberName, age]
Enqueue(queue, item)
input("Press Enter to continue...")
elif ch == 2 :
item = Dequeue(queue)
if item == "Underflow" :
print ("Underflow! Queue is empty!")
else :
print("Deleted item is", item)
input("Press Enter to continue...")
elif ch == 3 :
Display(queue)
input("Press Enter to continue...")
elif ch == 4 :
break
else :
print ("Invalid choice!")
input("Press Enter to continue...")
OR
i. list overheads = 26
Reference pointer size = 4 bytes (on 32 bit implementation)
Length of the list =3.
Memory consumption for list = 3
List overheads + Reference points size x
length of the list.
= 36 + 4 3 = 48 bytes.
ii. Memory consumption by data.
There are 3 values
1. integer i.e. 40
memory consumption = 12 bytes
2. float i.e. 40.5
memory consumption = 16 bytes
3. string i.e. "Ekta"
iii. memory consumption = overloads + 1 * string length
= 21 bytes + 1 * 4
= 21 + 4 = 25 bytes
memory consumption by data = 12 + 16 + 25 = 53 bytes
memory consumption for list l including actual data = 48 + 53 = 101 bytes
CBSE SAMPLE PAPER-02 (2020-21)
Class 12 Computer Science
Maximum Marks: 70
Time Allowed: 3 hours
General Instructions:
1. This question paper contains two parts A and B. Each part is compulsory.
2. Both Part A and Part B have choices.
3. Part-A has 2 sections:
a. Section – I is short answer questions, to be answered in one word or one line.
b. Section – II has two case study questions. Each case study has 4 case-based subparts.
An examinee is to attempt any 4 out of the 5 subparts.
4. Part - B is the Descriptive Paper.
5. Part- B has three sections
a. Section-I is short answer questions of 2 marks each in which two questions have
internal options.
b. Section-II is long answer questions of 3 marks each in which two questions have
internal options.
c. Section-III is very long answer questions of 5 marks each in which one question has
an internal option.
6. All programming questions are to be answered using Python Language only
a. sys.platform
b. sys.readline
c. sys.path
d. sys.argv
3. How will you open a new binary file btext.txt in write and read mode?
b. a = b = c = 1,000,000
d. abc = 1,000,000
a. c, d
b. b, d
c. a, c
d. a, d
8. What will be the result of following statement with following hierarchical structure of
package Pkt1
i. _int_.py
ii. module1
iii. module2
iv. module3
11. Can you suggest a real-life application for input/output restricted queues?
12. What do you understand by the terms Candidate Key and Cardinality of relation in
the relational database
14. A(n) ________ in a table represents a logical relationship among a set of values.
a. Entry
b. Key
c. Attribute
d. Tuple
15. Expand the following:
i. VoIP
ii. SMTP
16. Which is the subset of SQL commands used to manipulate database structures,
including tables?
a. None of these
b. Both Data Definition Language (DDL) and Data Manipulation Language (DML)
18. What do you understand by Primary Key? Give a suitable example of Primary Key
from a table containing some meaningful data.
a. 1
b. 2
c. none of these
d. 0
22. Consider the following tables GAMES and PLAYER and answer (b) and (c) parts of this
question:
Table: GAMES
GCode Game Name Type Number Prize Money Schedule Date
Table: PLAYER
3 Jatin 101
4 Nazneen 103
i. Write a user-defined function to display the total number of words present in the
file.
ii. Which of the following function flushes the files implicitly?
a. flush()
b. close()
c. open()
d. fflush()
iii. A __________ function reads first 15 characters of file.
iv. You can create a file using _________ function in python.
v. A _____ function requires a sequence of lines, lists, tuples etc. to write data into file.
Part – B (Section-I)
24. Rewrite the following code in python after removing all syntax error(s).
Underline each correction done in the code.
30 = To
for K in range(0,To)
IF k%4== 0:
print (K * 4)
Else:
print (K + 3)
25. Write the expanded names for the following abbreviated terms used in Networking
and Communications
i. GPRS
ii. WiFi
iii. POP
iv. SMTP
OR
OR
Find the error(s) in the following code and correct them:
def describe intelligent life form():
height = raw_input ("Enter the height")
rawinput ("Is it correct?")
weight = raw_input ("Enter the weight")
favourite-game = raw_input ("Enter favorite game")
print "your height", height, ’and weight', weight
print "and your favourite game is", favouritism, '.'
28. Consider the following nested list definition and then answer the questions based on
this
x = [10, [3.141, 20, [30, 'baz', 2.718]], 'foo']
A schematic for this list is shown below:
29. Find and write the output of the following python code:
def Change(P, Q = 30):
P=P+Q
Q=P-Q
print(P,"#",Q)
return (P)
R = 150
S = 100
R = Change(R,S)
print(R, "#",S)
S = Change(S)
30. In a table Apply, there is a column namely Experience that can store only one of
these values: 'Fresher', 'Private-sector-experience', 'Public-sector-experience', 'Govt.-
sector experience'. You want to sort the data of table based on column experience as
per this order: 'Govt-sector-experience', 'Public-sector-experience', 'Private-sector-
experience', 'Fresher'. Write an SQL query to achieve this.
i. arr = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
arr[i - 1] = arr[i]
for i in range(0, 6):
print(arr[i], end = " ")
ii. Numbers = [9, 18, 27, 36]
for Num in Numbers :
for N in range(1, Num%8) :
print(N, "#", end = " ")
print( )
Section- II
34. Write a function CountYouMe() in Python which reads the contents of a text file
Notes.txt and counts the words You and Me (not case sensitive).
35. Write a function called removeFirst that accepts a list as a parameter. It should
remove the value at index 0 from the list.
Note that it should not return anything (returns None). Note that this function must
actually modify the list passed in, and not just create a second list when the first item
is removed. You may assume the list you are given will have at least one element.
OR
i. A name inside the parentheses of a function header that can receive value.
ii. An argument passed to a specific parameter using the parameter name.
iii. A value passed to a function parameter.
iv. A value assigned to a parameter name in the function header.
v. A value assigned to a parameter name in the function call.
vi. A name defined outside all function definitions.
vii. A variable created inside a function body.
i. default arguments
ii. keyword arguments
Section-III
39. Consider the following table STORE. Write SQL commands for the following
statements.
Table: STORE
Sharpener
2005 23 60 8 31-Jun-09
Classic
Gel Pen
2002 21 150 12 24-Feb-10
Premium
i. To display details of all the items in the Store table in ascending order of LastBuy.
ii. To display ItemNo and Item name of those items from Store table whose Rate is
more than 15 Rupees.
iii. To display the details of those items whose Suppliers code (Scode) is 22 or Quantity
in Store (Qty) is more than 110 from the table Store.
iv. To display the Minimum Rate of items for each Supplier individually as per Scode
from the table store.
40. Write a program that depends upon the user's choice, either pushes or pops an
element in a stack.
OR
Convert the expression (TRUE and FALSE) or not (FALSE or TRUE) to postfix
expression. Show the contents of the stack at every step.
12 Computer Science Sample Paper -02
Class 12 - Computer Science
Solution
2. We define a function in the program for decomposing complex problems into simpler
pieces by creating functions and for reducing duplication of code by calling the
function for specific task multiple times.
6. The Python search path is a list of directories that the Python searches for any Python
package or module to be imported.
8. This will given an error as importing a packet does not place any of modules into local
namespace.
9. Lists are mutable sequence types while tuples are immutable sequence types of
Python.
10. An argument is a value sent onto the function from the function call statement.
e.g. sum(4,3) have 4 and 3 as arguments which are passed to sum() function.
11. To store a web browser's history, the deque is used. Recently visited URLs are added
to the front of the deque, and the URL at the back of the deque is removed after some
specified number of insertions at the front.
12. Candidate key: It is a set of attributes that uniquely identify tuples in a table.
Candidate Key is a super key with no repeated attributes.
Cardinality of a relation represents the number of rows in the relation.
13. Overflow refers to when one tries to push an item in stack that is full.
fetchone() fetchall()
18. Primary Key: A column or set of columns that uniquely identifies a row within a
table is called a primary key.
For example, in the following table Student, the column Roll no. can uniquely
identify each row in the table, hence Roll no. is the primary key of the following table.
2 - - -
3 - - -
4 - - -
19. Switch is responsible for filtering i.e., transforming data in a specific way and for
forwarding packets of the message being transmitted, between LAN segments.
A switch does not broadcast the messages, rather it unicasts the message to its
intended destination.
23. (i) User define function to display total number of words in a file:
def countwords():
s=open ("Quotes.txt", 'r')
f = s, read()
z = f. split()
count=0
for i in z:
count=count +1
print("Total number of words", count)
(ii) b. close()
(iii) read(15)
(iv) open()
(v) writelines()
Part – B (Section-I)
OR
26. An Internet Protocol (IP) address is a numerical identification and logical address that
is assigned to devices connected in a computer network. An IP address is used to
uniquely identify devices on the internet and so one can quickly know the location of
the system in the network.
In a network, every machine can be identified by a unique IP address associated with
it and thus help in providing network security to every system connected in a
network.
OR
30. Statement:-
SELECT * FROM Apply ORDER BY FIELD (Experience, 'Govt-sector-experience', 'Public-
sector-experience', 'Private-sector-experience', 'Fresher') ;
i. Single Row (or Scalar) functions, work with a single row at a time. A single row
function returns a result for every row of a queried table.
ii. Multiple Row (or Group or Aggregate) functions, work with data of multiple rows
at a time and return aggregated value.
i. 2 3 4 5 6 6
ii. 1 #
1#2#
1#2#3#
Section- II
34. CountYouMe function will count the number of occurences of word You and Me in the
file given.
def CountYouMe():
wordlist = [line.strip() for line in open(‘Notes.txt’)]
# Searching for a word in a file
count =0
for word in wordlist:
words = word.split(" ")
for word in words:
# Remove all leading and trailing white spaces
word =word.strip().lower()
if word == 'you' or word=='me'():
count = count + 1
if count == 0:
print ("Not found in file")
else:
print ("count=", count)
Example: If the file contains
You are my best friend
You and me make a good team.
Output would be: count=3
OR
i. Parameter
ii. Named argument
iii. Argument
iv. Default value
v. Named/keyword arguments
vi. Global Variable
vii. Local Variable
36. As the application program grows larger in size with a lot of modules, we place
similar modules in one package and different modules in different packages. This
makes a project easy to manage and conceptually clear.
37. i. The default parameters are parameters with a default value set to them. This
default value is automatically considered as the passed value WHEN no value is
provided for that parameter in the function call statement.
Thus default arguments are useful when we want to skip an argument in a
function call statement and use the default value for it instead.
ii. The keyword arguments give complete control and flexibility over the values sent
as arguments for the corresponding parameters. Irrespective of the placement and
order of arguments, keyword arguments are correctly matched. A keyword
argument is where you provide a name to the variable as you pass it into the
function.
Section-III
38. Internet Protocol (IP) is a set of technical rules that define how computers
communicate over a network. There are currently two versions: IP version 4 (IPv4)
and IP version 6 (IPv6).
IPv4 was the first version of Internet Protocol to be widely used and still accounts for
most of today's Internet traffic. There are just over 4 billion IPv4 addresses. While that
is a lot of IP addresses, it is not enough to last forever. IPv4 and IPv6 are internet
protocol version 4 and internet protocol version 6, IP version 6 is the new version of
Internet Protocol, which is way better than IP version 4 in terms of complexity and
efficiency.
IPv6 is a newer numbering system to replace IPv4. It was deployed in 1999 and
provides far more IP addresses, which should meet the need well into the future.
The major difference between IPv4 and IPv6 is the number of IP addresses. Although
there are slightly more than 4 billion IPv4 addresses, there are more than 16 billion-
billion IPv6 addresses.
Number of
2^32 2^128
addresses
39. i. SELECT *
FROM STORE
ORDER By LastBuy ;
ii. SELECT ItemNo, Item
FROM STORE
WHERE Rate >15 ;
iii. SELECT *
FROM STORE
WHERE Scode = 22 OR Qty > 110 ;
iv. SELECT Scode, Min(Rate)
FROM STORE
GROUP By Scode;
40. push and pop operation into the stack:-
MAX_SIZE = 1000
stack = [0 for i in range(MAX_SIZE)] -
top = 0
def push():
global stack, top
x = int( input ("Enter element to push into stack: " ))
if top >= MAX_SIZE:
print("Cannot push. Stack is full. Overflow!")
else:
stack[top] = x
top += 1
def pop():
global stack, top
if top == 0:
print("Cannot pop. Stack is empty. Underflow!")
else:
top -= 1
def printStack():
print(stack[:top])
# __main__
while True:
print("Please choose operation")
print("1. Push")
print("2. Pop")
print("3. Print")
print("4. Exit")
choice = int(input("Please enter 1/2/3 : " ))
if choice == 4:
break
elif choice == 3:
printStack()
elif choice == 2:
pop( )
elif choice == 1:
push()
else:
print("Please give a correct input")
OR
(TRUE and FALSE) or not (FALSE or TRUE)]
Adding ] to the end of the expression and inserting [ to the beginning of the stack.
0 [
1 ( [(
2 TRUE TRUE