Practicing the CBSE Sample Papers for Class 12 Computer Science Set 2 allows you to get rid of exam fear and be confident to appear for the exam.
CBSE Sample Papers for Class 12 Computer Science Set 2 with Solutions
Section-A
Question 1.
State True/ False: A dictionary is ordered by index.
Answer:
False. A dictionary is not ordered by index. Dictionaries have keys, not index.
Questions 2.
The module required to use the mode function is :
(a) math
(b) statistics
(c) random
(d) Pandas
Answer:
(b) statistics
Question 3.
Which of the following operators perform an integer division
(a) *
(b) //
(c) /
(d) **
Answer:
(b) //
Question 4.
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
Answer:
(c) 36
Question 5.
Given : s=”AISSE@2023″. What will be the output of: print(s[-l: :-l])
(a) ‘3202@ESSIA’
(b) 3
(c) AISSE
(d) ESSIA
Answer:
(a) ‘3202@ESSIA’
Question 6.
Which of the following functions write data to a binary file :
(a) pickle( )
(b) writer( )
(c) load( )
Answer:
(d) dump( )
Fill in the blank:
Question 7.
______ command modifies the data of a table.
(a) Update
(b) Change
(c) Alter
(d) Modify
Answer:
(a) Update
Explanation: Update is a DML command that can be used to make changes to the data of the table.
Question 8.
Which of the following is not a category of SQL commands:
(a) DDL
(b) TCL
(c) DML
(d) None of these
Answer:
(d) None of these
Explanation: DDL, DML, TCL are all categories of SQL commands.
Question 9.
In the following code, which lines will give error (Assume the lines are numbered starting from 1): mul=3
value=10
for i in range (1, 6,1):
if (value % mul = 0):
print (value * multiply)
else
print (value + multiply)
(a) 4,5
(b) 4,5,6
(c) 4,5,6,7
(d) No errors
Answer:
(c) 4,5,6,7
Fill in the blank:
Question 10.
A primary key of a relation must be ______
(a) Unique Only
(b) NOT NULL Only
(c) Both Unique and NOT NULL
(d) Neither UNIQUE nor NOT NULL
Answer:
(c) Both Unique and NOT NULL
Question 11.
Which of the following functions will read entire contents of a text file?
(a) read( )
(b) readfull( )
(c) readline( )
(d) readfile( )
Answer:
(a) read( )
Fill in the blank:
Question 12.
The ______ clause can group records on the basis of common values in a field.
(a) aggregate
(b) group
(c) Group by
(d) Join
Answer:
(c) Group by
Fill in the blank:
Question 13.
______ is the base protocol for all application protocols.
(a) FTP
(b) TCP/IP
(c) IRCP
(d) Telnet
Answer:
(b) TCP/IP
Question 14.
Identify the output of the following Python statement, lst1 = [10,15, 20, 25, 30]
lst1.isert (3,4)
lst1.isert (2, 3)
print (lstl [-5])
(a) 2
(b) 3
(c) 4
(d) 20
Answer:
(b) 3
Explanation: The two insert statements insert the values at certain positions. After insertions the element at position -5 is displayed.
Question 15.
The first integrity rule for relational databases ensures that ______:
(a) Primary key is unique
(b) Foreign key is unique
(c) Primary key is unique and NOT NULL
(d) There is only one candidate key
Answer:
(c) Primary key is unique and NOT NULL
Question 16.
______ method creates a cursor object while connecting a python application with a Mysql database.
(a) connect( )
(b) createcursor( )
(c) getcursor( )
(d) cursor( )
Answer:
(d) cursor( )
Q. 17 and 18 are Assertion and Reasoning based questions. Mark the correct choice as :
(a) Both A and R are true and R is the correct explanation for A
(b) Both A and R are true and R is not the correct explanation of A
(c) A is True but R is False
(d) A is false but R is Ture
Question 17.
Assertion (A): A python function that accepts parameters can be called without any parameters.
Reason (R): Functions can car’ iefault values that are used, whenever values are not received from calling function.
Answer:
(a) Both A and R are true and R is the correct explanation for A
Explanation: While defining functions they may carry default values that can be used, if the function does not receive any values in the formal parameters. This gives more flexibility in using the functions.
Question 18.
Assertion (A): A CSV file is by default delimited by comma/,), but the delimiter character can be changed.
Reason (R): The writerow/) function for csv files has a “delimiter” parameter that can be used to specify the delimiter to be used for a CSV file.
Answer:
(a) Both A and R are true and R is the correct explanation for A
Explanation: While writing CSV files, if no delimiter is specified the default delimiter used is comma The delimiter parameter can be used to specify any other delimiter.
Section-B
Question 19.
Find the error(s).
LI = [7, 2, 3, 4] Statement 1
L3 = L1 * 2 Statement 2
L 2 = L1 + 2 Statement 3
L = L1 pop(7) Statement 4
Answer:
Error 1 L2 = L1 + 2 because + operator cannot add list with other type as number or string.
Error 2 L = L1.pop(7) parentheses puts index value instead of element. In the given list, maximum index value is 3 and 7 is out of index range.
Corrected code:
LI = [7,2,3,4]
L3 = LI*2
L2 = LI*2
L = Ll.pop( )
Question 20.
Differentiate Bus and Star topology.
OR
Differentiate HUB and Switch.
Answer:
Bus topology | Star topology |
1. Economically feasible | 1. Costly structure |
2. A single central cable | 2. Separate cables for each node. |
OR
HUB | Switch |
1. It cannot filter network traffic | 1. It can filter network traffic |
2. Broadcasts data. | 2. Multiple pair of communications are possible. |
Question 21.
(a) What will be the output of the following Python code?
L = [10, 20]
L1 = [30,40]
L2 = [50, 60]
L.append(L.1)
L.extend(L.2)
(a) [60, 50, 40, 30, 20,10]
(b) [10, 20, 30, 40, 50, 60]
(c) [10, 20, 30, 40, [50, 60]]
(d) [10, 20, [30, 40], 50, 60]
(b) Find the output.
>>>l1 = [1, 2, 3, 4]
>>>l2 = [2, 3, 4, 5]
>>>l1 > 12
Answer:
(a) (d) [10, 20, [30, 40], 50, 60]
(b) False
Question 22.
Differentiate between an attribute and a tuple with an example.
Answer:
The columns of a table are referred to as attributes. It is also known as field which is reserved for a specific piece of data. The rows of a table are referred to as tuples.
Attributes
S. No. | Name | Class | |
Tuples | 1 | Raj | 10 |
2 | Ajay | 12 | |
3 | Rahul | 11 |
Question 23.
(a) Write the full forms of the following:
(i) WAN
(ii) GSM
(b) Write down the expnsion of Modem. Also write its role in a network.
Answer:
(a) (i) Wide area network.
(ii) Global system for mobile communication.
(b) A Modem stands for Modulator – Demodulator. It is a network device used for conversion of signals from Digital to Analog and Analog to digital.
Question 24.
Predict the output
die = {‘a’: 1, ‘b’: 2, ’c’: 3. ‘d’: 4)
print(d i c)
if ’a’ in die
del dief’a’]
print(dic)
OR
Identify the output of the following Python code.
D = {1 : “One”, 2 : “Two”, 3 : “Three”)
L = [ ]
for K, V in D.items( ):
if V[0] =”T”
L.append (K)
print(L)
(a) [1, 2, 3]
(b) [“One”, “Two”, “Three”]
(c) [2,3]
(d) [“Two”, “Three”]
Answer:
Output
{‘d’: 4, ‘a’: 1,’c’: 3, ‘b’: 2}
{’d’: 4, V : 3, ‘b’: 2}
OR
Answer:
(c) [2,3]
Question 25.
Differentiate Primary key and Unique constraints.
OR
Categorise the following commands as DDL or DML.
Primary key | Unique |
1. Only one field in a relation can have Primary key constraint. | 1. Multiple fields can have Unique constraints. |
2. Applying it ensures that the column will have unique and NON NULL values. | 2. Ensures UNIQUE values only. |
OR
Answer:
DDL is Data Definition Language which is used to define data structure —> SELECT, ALTER.
DML is Data Manipulation Language which is used to manipulate data itself. DELETE, DESCRIBE
Section-C
Question 26.
(a) Consider the tables cars and Supplier given below . What will be the output of the statement given:
Table: CITY
FIELD NAME | DATA TYPE | REMARKS |
CITYCODE | CHAR(S) | PRIMARYKEY |
CITYNAME | CHAR(30) | |
SIZE | INTEGER | |
AVGTEMP | INTEGER | |
POPULATIONRATE | INTEGER | |
POPULATION | INTEGER |
Table: Location
Citycode | Lname |
C1 | East |
C2 | West |
C3 | South |
C4 | North |
Write a command to display the cityname and corresponding Location name (Lname) where the average temperature is greater than 35, from the tables.
(b) Write outputs for the SQL commands (i) to (iv) based on the table Customer given below:
TABLE : CUSTOMER
CNAME | GENDER | SID | AREA |
RSHARMA | FEMALE | 101 | NORTH |
M R TIWARY | MALE | 102 | SOUTH |
M K KHAN | MALE | 103 | EAST |
A K SINGH | MALE | 102 | EAST |
S SEN | FEMALE | 101 | WEST |
R DUBEY | MALE | 104 | NORTH |
M AGARWAL | FEMALE | 104 | NORTH |
S DAS | FEMALE | 103 | SOUTH |
R K PATIL | MALE | 102 | NORTH |
N KRISHNA MURTY | MALE | 102 | SOUTH |
(i) SELECT COUNT (*), GENDER FROM CUSTOMER GROUP BY GENDER;
(ii) SELECT CNAME FROM CUSTOMER WHERE CNAME LIKE ‘L%’;
(iii) SELECT DISTINCT AREA FROM CUSTOMER;
(iv) SELECT COUNTf) FROM CUSTOMER WHERE GENDER=”MALE”;
Answer:
(a) Select C. Cityname, L.Lname from City C, Location L where C.Citycode= L. Citycode;
(b) (i)
COUNT(*) | GENDER |
4 | FEMALE |
6 | MALE |
(ii) No rows selected
(iii)
DISTINCT AREA |
NORTH SOUTH EAST WEST |
(iv)
Count(*) |
5 |
Question 27.
Write a function Del( ) to delete the 4th word from a text file school.txt.
OR
Write a program in python to open a text file “lines.txt” and display all those words whose length is greater than 5.
Answer:
def Del ( ):
with open (‘school.txt’. ‘r’ as f:
l = f. readlines( )
f.close( )
print(l)
del l[3]
print(l)
f = open (‘school.txt’, ‘w’)
f.writelines(l)
i f.close( )
OR
f=open(“lines.txt”)
data=f.read( )
str=data.split(”)
print(“Words with length greater than 5”)
for w in str:
if len(w)>5:
print(w)
f.close( )
Question 28.
(a) Consider the following tables. Write SQL commands for the statements (i) to (iv).
Table: SENDER
SenderID | SenderName | SenderAddress | SenderCity |
ND01 | R Jain | 2, ABC Appis | New Delhi |
MU02 | H Sinha | 12, Newtown | Mumbai |
MU15 | S Jha | 27/A, Park Street | Mumbai |
ND50 | T Prasad | 122-K, SDA | New Dewlhi |
Table: RWCIPIENT
RecID | SenderID | RecName | RecAddress | RecCity |
KO05 | ND01 | R Bajpayee | 5, Central Avenue | Kolkata |
ND08 | MU02 | S Mahajan | 116, A Vihar | New Delhi |
MU19 | ND01 | H Singh | 2A, Andheri East | Mumbai |
MU32 | MU15 | P K Swamy | B5, C S Terminus | Mumbai |
ND48 | ND50 | S Tripathi | 13, B1 D. Mayur Vihar | New Delhi |
(i) To display the names of all Senders from Mumbai.
(ii) To display the RecID, SenderName, Sender Address, RecName, RecAddress for every Recipient.
(iii) To display Recipient details in ascending order of RecName.
(iv) To display number of Recipients from each City.
(b) Display the Sender name and corresponding Recipient name from the tables where sender is from “NEW DELHI” and recipient is from “KOLKATA”
Answer:
(a) (i) SELECT SenderName FROM SENDER WHERE SenderCity = ‘Mumbai’:
(ii) SELECT RecID, SenderName,
Sender Address, RecName, RecAddress
From RECIPIENT, SENDER WHERE
RECIPIENT. SenderlD = SENDER.SenderlD;
(iii) SELECT * FROM RECIPIENT ORDER BY RecName:
(iv) SELECT COUNT (*) AS “No. of Recipients”, RecCity FROM RECIPIENT
GROUP BY RecCity:
(b) Select SenderName, RecName from Sender S , Recipient R where S.SenderID=R.senderID and (SenderCity=”NDLS” and RecCity=”KOLKATA”);
Question 29.
Write a user defined function parser(L) that accepts a list as parameter and creates another two lists storing the numbers from the original list, that are even and numbers that are odd.
Answer:
newLeven=[ ]
newLodd=[ ]
i=j=0
def parser(L):
for num in L :
if num%2 =0:
newLeven [i] =num
i+=l
else:
newLodd[j]=num
j+=l
print(“Even number list:” , newLeven)
print(“Odd number list:” , newLodd)
Questions 30.
Consider the following stack of characters, where STACK is allocated N=8 memory cells.
STACK: A, C, D, F, K, …, …., ….,
Describe the STACK at the end of the following operations. Here, Pop and Push are algorithms for deleting and adding an element to the stack.
(i) Pop (STACK, ITEM)
(ii) Pop (STACK, ITEM)
(iii) Push (STACK, L)
(iv) Push (STACK,P)
OR
Consider the following sequence of number:
1,2, 3,4
These are supposed to be operated through a stack to produce the following sequence of numbers:
2,1,4, 3
List the Push and Pop operations to get the required output.
Answer:
The stack contents will be as follows after the opeations of stack.
(i) STACK :A,C,D,F (K is deleted)
(ii) STACK: A,C,D (F is deleted)
(iii) STACK: A, C, D, L (L is inserted)
(iv) STACK: A, C, D, L, P. (P is inserted)
(v) STACK: A, C, D, L (P is deleted)
(vi) STACK: A, C, D, L, R (R is inserted)
(vii) STACK: A, C, D, L, R, S (S is inserted)
(viii) Stack: A, C, D, L, R (S is deleted)
Answer:
(i) Push (1)
(ii) Push (2)
(iii) Pop (2)
(iv) Pop(1)
(v) Push (3)
(vi) Push (4)
(vii) Pop (4)
(viii) Pop (3)
Section-D
Question 31.
Trine Tech Corporation (TTC) is a professional consultancy company. The company is planning to set up their new offices in India with its hub at Hyderabad. As a network adviser, you have to understand their requirement and suggest them the best available solutions. Their queries are mentioned as (i) to (v) below.
Physical locatioons of the blocks of TTC
Block to block distance (in m)
Block (From) | Block (To) | Distance |
Human Resource | Conference | 110 |
Human Resource | Finance | 40 |
Conference | Finance | 80 |
Expected number of computers to be in each block
Block | Computer |
Human Resource | 25 |
Finance | 120 |
Conference | 90 |
(i) Which will be the most appropriate block, where TTC should plan to install their server?
(ii) Draw a block to block cable layout to connect all the buildings in the most appropriate manner for efficient communication.
(iii) Suggest a suitable topology to connect the computers in each building.
(iv) Which of the following devices will be suggested by you to connect each computer in each of the buildings?
- Switch
- Modem
- Gateway
(v) Company is planning to connect its offices in Hyderabad which is les than 1 km. Which type of network will be formed?
Answer:
(i) TTC should install its server in finance block as it is having maximum number of computers.
(ii)
The above layout is based on minimum cable length required, which is 120 metres in the above case.
(iii) Star topology, as it has independent connections that help easy network setup and fault detection.
(iv) Switch/Hub : These are devices that can connect multiple nodes in a network, together.
(v) Since the distance is less than 1KM, LAN – Local area network will be formed.
Question 32.
(a) 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#
(b) Given below is a table item in database inventory.
ItemID | ItemName | Quantity | UnitPrice |
101 | ABC | 5 | 120 |
102 | XYZ | 7 | 70 |
103 | PQR | 8 | 65 |
104 | XYZ | 12 | 55 |
Riya created this table but forget to add column Manufacturing Date. Can she add this column after creation of tables? If yes, write the code where user’s name and password are system and test respectively.
Note the following to establish the connection between python and MySQL:
Host: localhost
Username: system
Password: test
Database: Inventory
Answer:
(a) (b) 50#5
(b) Yes, she can add new column after creation of table,
import mysql. connector
mycon = mysql. connector.connect
host = “localhost”,
user = “system”,
passwd = “test”,
database = “Inventory”)
cursor = mycon.cursor ( )
cursor.execute (“ALTER TABLE Item ADD ManufacturingDate Date NOT NULL”)
mycon.close( )
OR
(a) Find the output of the following code.
Name “Python301″
R=” “.
for x in range (len(Name)):
if Name(x). lsupper ( )
R=R+Name[x].lower( )
elif Name[x].is lower( ):
R=R+Name(x).upper( )
el if Name[x].isdigit( )
R=R+Name[x-1]
else:
R=R+”#”
print(R)
(a) pYTHOn##@
(b) pYTHOnN#@
(c) pYTHOn#@
(d) pYTHOnN@#
Answer:
(b) Consider the following table structure
Table: Faculty with fields as
F_ID(P)
Fname
Lname
Hire_date
Salary
Write the Python code to create the above table.
Consider:
host: loalhost
UserName: root
Pasword: system
Database :School
Answer:
(a) (b) pYTHONn#@
(b) import mysql.connector
mycon = mysql.connector.connect (
host = “localhost”,
user = “root”,
passwd = “system”,
database = “School”)
cursor = mycon.cursor( )
db = cursor.execute (“CREATE TABLE Faculty”(
F_ID varchar (3) Primary key.
Fname varchar (30) NOT NULL,
Lname varchar (40),
Hire_date Date,
Salary Float))
mycon.close( )
Question 33.
(a) Write the different text file reading functions in python.
(b) Write a python code to read a text file “emp.txt” and display the file contents if contains odd number of lowercase vowels. Otherwise it displays the number of such vowels.
OR
(a) Write the random access functions in file handling. Also explain the uses of the functions.
(b) Write a python code to open a text file “notes.txt” and display all the words that end with a lowercase vowel.
Answer:
(a) Text file reading functions:
(i) read( ) – Reads the entire contents of the file dtarting from the current position.
(ii) read(n) – Reads n characters from the text file.
(iii) readline( ) – Reads a line from a text file.
(iv) readlines( ) – Reads each line of the file as a list item in a list comprising all the lines.
(b) f=open(“emp.txt”)
filedata=f.read( )
count=0
for ch in filedata:
if ch in “aeiou”:
count+=1
if count%2 =0:
print(filedata)
else:
print(count)
OR
Answer:
(a) The random access functions in python are:
(i) seek(n) – The seek() function places the file pointer at the position indicated by n.
(ii) tell( ) – The tell function returns the current position of the file pointer.
(b) f=open(“notes.txt”)
filedata=f.read( )
count=0
print(filedata)
data=filedata.split(‘ ‘)
for words in data :
if words[-l] in “aeiou”:
print(words)
f.close( )
Section-E
Question 34.
Consider the following tables STORE and answer the questions:
Table: STORE
ItemNo. | Item | Scode | QTY | Rate | LastBuy |
2005 | Sharpener Classic | 23 | 60 | 88 | 31-Jun-09 |
2003 | Balls | 22 | 50 | 25 | 01-Feb-10 |
2002 | Gel Pen Premium | 21 | 150 | 12 | 24-Feb-10 |
2006 | Gel Pen Classic | 21 | 250 | 20 | 11-Mar-09 |
2001 | Eraser Small | 22 | 220 | 6 | 19-Jan-09 |
2004 | Eraser Big | 22 | 110 | 8 | 02-Dec-09 |
2009 | Ball Pen 0.5 | 21 | 180 | 18 | 03-Nov-09 |
(i) What is the degree of the table .
(ii) Write the Syntax of the SQL command to change data of the table.
(iii) Write statements to :
(a) Display the number of distinct Scodes.
(b) Display the maximum and minimum quantities.
OR (OR Part only for part iii)
(iii) Write statements to:
(a) Display the structure of the STORE table
(b) Add a new column Location Varchar(50) in the table to store the location details of the items.
Answer:
(i) Degree means the number of columns in a table. The degree of the table is : 6
(ii) Update <Table> Set <Column> = <Value/Expression> where <Condition>
(iii) (a) Select count(Distinct Scode) from STORE;
(b) Select Max(Qty), Min(Qty) from STORE;
OR
(iii) (a) Describe STORE;
(b) Alter table STORE ADD Location varchar(50);
Question 35.
Given below is a code to open a text file “para.txt” and display the lines that begin with “A”. Some of the codes are missing . Write codes to fill up the blanks :
myf=open(…………., …………..) Blank 1, Blank 2
lines=myf ………………. Blank 3
for In in ………….: Blank 4
if ln[0]=”A”:
print(ln)
(i) Write the missing code for Blank 1, Blank 2.
(ii) Write the missing code for Blank 3.
(iii) Write the missing code for Blank 4.
Answer:
(i) “para.txt” , “r”
(ii) readlines( )
(iii) lines