You are on page 1of 9

Sample Paper 5 Solutions

Computer Science (083)

CLASS XII 2023-24


Time: 3 Hours Max. Marks: 70

General Instructions:

I. Please check this question paper contains 35 questions.

2. The paper is divided into 4 Sections- A, B, C, D and E.

3. Section A, consi sts of 1 8 questions ( I to 18). Each question carries I Mark

4. Section B, consists of7 questions ( 1 9 to 25). Each question carries 2 Marks.

5. Section C, consi sts of 5 questions (26 to 30). Each question carries 3 Marks.

6. Section D, consists of2 questions ( 3 1 to 32). Each question carries 4 Marks.

7. Section E, consists of3 questions (33 to 35). Each question carries 5 Marks.

8. All programming questions are to be answered using Python Language only.

5. Given : s= "Computer Sxam". What will be the

Section A output of

p r i n t ( s [ 2 ] + s [ 8 ] + s [ l : 5 1 ) ?

1. _ _ _ _ _ command modifies or change the existing (a) n1EOMUU (b) mlioinpu

records in a table. (c) n1Eo1nPU (cl) MEompu

(a) UPDATE
Sol:
(b) CHANGE

(c) ALTER (b) mliompu

(cl) MODIFY
6. State True or False

Sol:
Digits are one of the parts of the Python character

(a) UPDATE set

Sol:
2. Which of the following operator cannot be used

with string data type? True

(a) + (b) in
7. The clause to arrange the data of a colu11111 in
(c) * (cl) I
descending order is

Sol :
(a) DESC (b) GROUP BY

(c) LIKE (cl) ASC


(cl) I

Sol:
3. Which of the following is a category of SQL

commands? (a) DESC

(a) DDL (b) TCL


8. Which of the following are the most obvious kind
(c) DML (cl) All of these
of constants?

Sol :
(a) Keywords (b) Literals

(cl) All of these (c) Variables (cl) Identifiers

Sol :
4. What is the output of the following code?

num - 4 + float (7)/int ( 2 . 0 ) (b) Literals

print ("num -", num)


9. Which of the following types of files will need the
(a) num = 7.5 (b) 7.5
pickle module for working on it ?
(c) num : 7.5 (cl) Error
(a) Binary files (b) Text files

Sol:
(c) CSV files (cl) All of these

(a) nun1=7.5
Sol:
Page 2 Sample Paper 1 Computer Science Class 12

(a) Binary files 15. Which of the following functions will read lines of

a text file as list elements.


10. In the following code, which lines will give error?
(a) read( )
( Assume the lines are numbered starting from 1 . )
(b) get()
mul-3
(c) reaclline( )
value=lO

(cl) reacllines( )
for 1 in range ( 1, 6, 1 ) :

if (value% mul - 0 ) :
Sol:
print (value* multiply)
(cl) reacllines( )
else

print (value+ multiply)


16. Which of the following will be the output of the
(a) 4,5
statement given below?
(b) 4,5,6
print ( [ 1 2 , 3 4 , 5 6 , 7 8 , 9 0 ] . pop ( I I
(c) 4,5,6,7
(a) 78 (b) 90
(cl) No errors
(c) 12 (cl) 12,34,56,78,90

Sol :
Sol :

(c) 4,5,6,7
(b) 90

11. There can be foreign keys in a relation.


Direction (Q.Nos. 17-18) are Assertion and
(a) 2 (b) 3
Reason based questions.
(c) 1 (cl) Multiple

17. Assertion (A) In a cross join the number of records


Sol :
in the output will be the maximum.
(cl) Multiple
Reason (R) A cross join is also called a Cartesian

product.
12. The clause with the COUNT() function
(a) Both A and R are true and R is the correct
counts only the unique values in an attribute.
explanation for A.
(a) UNIQUE

(b) HAVING (b) Both A and R are true but R is not the

(c) DISTINCT correct explanation for A.

(cl) LIKE (c) A is true but R is false.

(cl) A is false but R is true.


Sol :

(c) DISTINCT Sol:

(b) Both A and R are true but R is not the correct


13. User can write Python script using
explanation for A.
(a) MySQL.connector library

(b) SQL.connect library 18. Assertion (A) A file that is opened using the

open() function may not specify the mode of


(c) MySQL.connect library
opening it.
(cl) None of these
Reason (R) If the mode is not specified , the read

mode is used by default ..


Sol :
(a) Both A and R are true and R is the correct

(a) MySQL.connector library explanation for A.

(b) Both A aocl R are true but R is not the


14. is a protocol used for remote login.
correct explanation for A.
(a) HTIT

(c) A is true but R is false.


(b) PPP

(c) IRCP (cl) A is false but R is true.

(cl) Telnet
Sol:

Sol:
(b) Both A and Rare true but R is not the correct

(cl) Telnet explanation for A.


Page 3 Sample Paper 1 Computer Science Class 12

23. (a) Write the full forms o f :


Section B
(i) POP (ii) HTTP

(b) Differentiate between the terms Internet and


19. Observe the given list and find the answer of
Intranet.
questions that follows.

listl = [23, 45, 63, 'Hello', 20 Sol :

'World', 15, 18]


(a) (i) Post Office Protocol.
(i) listl [ - 3 ] (ii) listl [ 3 ]
(ii) HyperText Transfer Protocol

Sol : (b) Differences between Internet and Intranet are

as follows
(i) 'Workl' (ii) 'Hello'

Internet Intranet

20. What is the advantage of using switch over hub?


Access by an individual Access by only

Sol : with dial-up access. authorised employees.

Switch provides a dedicated line at full bandwidth


Information on Information on

between two devices but hub does n't provide a


Internet could be Intranet could be

dedicated line. Hub share the bandwidth.


general, public and specific, corporate and

or advertisement. proprietary.

Write some benefits of networking.

24. Predict the output


Sol :
d i e = { ' a ' : 1 , ' b ' : 2 , ' e ' : 3 , ' d ' : 4 }

Some of the benefits of networking are print ( d i e )

(i) File sharing if 'a' in die ·

(ii) Hard ware sharing del die [ ' a ' ]

(iii) Application sharing print ( d i e )

(iv) User communication


Sol :
(v) Access to remote database

Output

21. (a) Find the output


{'d' : 4, 'a' : 1, 'c' : 3, 'b' : 2}

L - [10, 19, 45, 77, 10, 22, 2 J


{'d' : 4, 'c' : 3, 'b' : 2}

( i ) L [ 3 : 5 ] (ii) L I : · - 2J
or

(b) Find the error( s).


Distinguish between tuple and list.

Ll - [ 7, 2, 3, 4 J
Sol:
L2 - Ll + 2

L3 - Ll * 2 Differences between tuple and list are as follows

L - L 1 . pop I 7 )
Tuple List

Sol : Elements of a tuple ace Elements of a list arc

immutable. mutable.
(a) (i) [77, 10] (ii) [2, 10, 45, 10]

Tuple is declared ,n List is declared m square


(b) Error 1 L2 Ll + 2 because + operator
parenthesis 0. brackets .
cannot add list with other type as number or
Tuples cannot be changed Lists can be changed after
string.
after creation. creation.

Error 2 L = Ll.pop(7) parentheses puts index


Iterating over the elements Iterating over the clements
value instead of element. In the given list,
of a tuple is fest. of a list is slow.

maximum index value is 3 and 7 is out of

index range. 25. Explain the concept of candidate keys with the

help of an appropriate example.


22. What do you understand by RDMS?

Sol:
Sol :

A candidate key is a set of one or more fields that


A Relational Database Management System
identifies each record uniquely in a table. There
(RDBMS) is a database management system. It
can be multiple candidate keys in one table and
is developed by Dr. E.F. Codd, of IBM's SAN
one of them will become the primary key.
Jose Research Laboratory.
e.g.
Page 4 Sample Paper 1 Computer Science Class 12

trains.
Table : Item

(b) Considering the tables Train and Travel given


INO !Name Qty
above write commands for the following :

101 CD 10
(i) Display passenger names 1
corresponding

102 Pen 5 train names and amounts for records

where amount >5000.


103 Pencil 2
(ii) Increase amount of passengers by 20%

104 Eraser 3 who are travelling by 'AC ll

In the Item table, INO and fName can be treated (iii) Display a cross join of the two tables.

as the candidate keys. (iv) Remove records of passengers who are

or travelling by "Rajdhani".

Observe the following table carefully and write


Sol:
the names of the most appropriate columns,

which can be considered as (i) candidate keys and (a) SELECT T r . Pname, T . Tname FROM

(ii) primary key. Travel Tr, Train T WHERE Tr.Tid =

T.Tid AND Tname LIKE "%Mail";


Table: Product

(b) (i) SELECT T l . Pname, T 2 . Tname,


CID CNAME AMOUNT COUNTRY ITEM
T l . Amt FROM Travel Tl, Train

101 ALLE 100000 JMEKA SI-IDES


T2 WHERE Tl .Tid- T2. Tid AND

111 BEN 20000 FRANCE HEL1v1ET Amt>5000;

(ii) UPDATE Travel SET


110 RJKI 25000 Alv!ERJCA BAG

A m t - Am t + Am t * 0 . 2 WHERE Class-
011 BRETT 105000 AUSTRALIA BAT
"AC";
LEE

(iii) S E L E C T * F R O M Travel, Train;


Sol :
(iv) DELETE FROM Travel Tr, Train

(i) Candidate Keys CID , ITEM T WHERE Tr.Tid - T.Tid AND

(ii) Primary key CID T.Tname="Rajdhani";

27. A binary file "emp.dat'' contains records of

employees as per following structure:


Section C
Eno Ename Salary

1 Mr. Raj 85000


26. (a) Consider the tables Travel and Train given

below.
Write a program in Python to open the Binary

file "emp.dat" and display only those records


Table : Travel

where the employee salary is greater than 75000.


Teno Pname Class Tld Amt

Sol:
1 R.ahul AC Tl 2500

import pickle
2 Sujit SL T2 4500
f=open ( " e m p . d a t " , "rb")

3 Ravi AC Tl 6000 while True:

try:
4 Ankita AC T3 1800
lst-pickle.load(f)

if (1st [2] >75000) ·


Table : Train
print("Employee No. . " l s t [ O J )
. '

Tld Tname print("Employee N a m e : " , l s t [ l ] )

print(''Employee Salary · " ,


Tl Rajdhani

lst[2J I

T2 Himgiri Exp
except EOFError:

T3 Darjeeling Mail print("No more records")

break
Write the command to display the passenger
f .close ( I
names and the train names by which they are
or
travelling for all passengers travelling by "Mail"
Page 5 Sample Paper 1 Computer Science Class 12

Write a program to read the content from a text


I ND50 I T Prasad I 122-K, SDA I New Delhi

file "status. txt" 1


count and display the total

number of lines and blank spaces present in it.


TABLE: RECIPIENT

e.g. if the "status.txt" file contains the following


RecID SenderlD RecName RecAddress RecCity
lines:

1(005 NDOI R Baj payee 5 Central Kolkata


Welcome to your one-step solutions for all your
'
Avenue
study, practice and assessment needs for various

NODS MU02 S Nlahajan llG, A Vihar New


competitive & recruitment examinations and
Delhi
school segment. \¥e have been working tirelessly

lv!Ul9 NDOI l·l Singh 2A, Andheri M umbai


for over a decade to make sure that you have
Ea.st
best in class study resources because you deserve

1v!U32 MU15 P K Swamy 85 c s M umbai


SUCCESS AND NOTHING LESS . . . '

Tenn.in us
The output will be:
ND48 ND50 S Tripathi 13, Bl D, New
The status file contents are
Mayur Delhi
Total lines in file are: 4
Vihar

Total spaces in file are: 43


(i) To display the names of all Senders from

Sol : Mumbai.

(ii) To display the RecID, Sender Name,


import os

SenderAddress, RecName, RecAddress


tfile='status.txt'

for every Recipient.


if os.path.isfile(tfile) ·

(iii) To display Recipient details in ascending


fob=open ( t f i l e , 'r')

order of Reclvame.
blankspaces=total lines=O

(iv) To display uumber of Recipients from


print("The status file contents

each City.
are")

(b) Display the Sender name and corresponding


print(" ")

Recipient name from the tables where sender


while True:

is from "NE\¥ DELHI" and recipient is from


aline=fob.readline()

"KOLKATA".
if not aline:

break Sol :

else:
(a) (i) SELECT SenderName FROM SENDER
total lines=total lines+!
WHERE SenderCity - 'Mumbai';
aline=aline.rstrip()
(ii) SELECT RecID, SenderName,
for i in aline:
SenderAddress, RecName,
if i.isspace() ·
RecAddress
blankspaces=blankspaces+l
FROM RECIPIENT, SENDER WHERE
print("Total lines in file are:
RECIPIENT.SenderlD SENDER.
%d'' %total lines)
Sender I D ;
print("Total space in file are:
(iii) S E L E C T *FROM RECIPIENT ORDER
%d'' % blankspaces)
BY RecName;
fob. c l o s e I )
(iv) S E L E C T COUNT ( * ) AS "No. of
else:
Recipients", RecCity FROM
print("File does not exist")
RECIPIENT GROUP BY RecCity;

28. (a) Consider the following tables SENDER and (b) SELECT SenderName, RecName

RECIPINT. Write SQL commands for the FROM Sender S , Recipient R

WHERE S.SenderlD-R.SenderID AND


statements (i) to (iv).

( SenderCi ty= "New Delhi" AND


TABLE: SENDER
RecCi ty="KOLKATA") ;

Sender ID Sender Name Sender Address SenderCity

29. Write a user defined function change(L) to accept


NDOl R Jain 2, ABC Appts New Delhi
a list of numbers and replace the numbers in the
1v!U02 H Sinha 12, Newtown Mumbai
list with their sum of digits.

i'vIU15 S Jha 27 /.4.., Park Street Mumbai Example


Page 6 Sample Paper 1 Computer Science Class 12

Input : [32,142,215,26,7] (1) (2) (3)


(4) 50

Output : [5, 7 , 8 , 8, 8,7] 50 50

200 200 200


Sol :
100 100 100 100
L- [ ]

(5) (6) ( 7) ,--,....---, (8)


n=int(input("Enter number of
50 2
element"))

200 200 200 200


for i in range (1, n + l ) :

b=int(input("Enter element:")) 100 100 100 100

L-append(b)

i-0

for a in L:

s-0 Section D
while a>O:

s+-a%10 31. Freshminds University of India is starting its first

a//-10 campus in Ana Nagar of South India with its

L[i]-s centre achnission office in Kolkata. The university

i+=l has three major blocks comprising of Office block,

print(L) Science block and Conunerce block is in 5 km area

campus.
30. Write Push (contents) and Pop() methods in
As a network expert, you need to suggest the
Python to add numbers and remove numbers
network plan as per (i) to (v) to the authorities
considering them to act as Push and Pop
keeping in mind the distance and other given
operations of stack.
parameters.

Sol :

/ / Freshminds
def Push (contents):
University

if(len(stack) > - l i m i t ) ·
Kolkata

Admission
Ana Naga, II �c· 11

Campus
print("Stack O v e r fl o w ! " ) Office

else : Office

Block
stack.append (contents) 1 1 1 1

Science
print ("Stack after Push", stack)
Block 11
11
def Pop ( I :

if (len (stack) <- 0 ) :

Expected wire distance between various locations.


print("Stack Underflow!")

return O Office Block to Science Block 90 111

else :
Office Block to Commerce Block 80 Ill

return stack.Pop( I
Science Block to Oornmerce Block 15 lll

or
Kolkata Admission Office to Ana Nagar 450 kin
Find the final contents of a stack on which the
Campus

following operations are clone.


Expected number of computers to be installed at
1. Push(lOO)
various locations in the university are as follows:

2. Push(200)
Office Block 10

3. Push(50)
Science Block 140

4. Push(50)
Commerce Block 30

5. Pop() Kolkata Admission Office 8

6. Push() (i) Suggest the authorities, the cable layout

amongst various blocks inside university


7. Pop(2)
campus for connecting the blocks.
8. Pop()
(ii) Suggest the most suitable place (i.e. block)

to house the server for this university with a


Sol :
suitable reason.
Page 7 Sample Paper 1 Computer Science Class 12

: " ) )
(iii) Suggest an efficient device from the following

a = x + y +
z
to be installed in each of the block to connect

print ("Result - ", a)


all the computers.

(b) import m y s q l . connector


(a) Modern (b) Switch (c) Gateway

mycon = mysql.connector.connect (
(iv) Suggest a suitable topology to connect the

h o s t = "local host",
computers in each building.

u s e r = "root",
(v) University is planning to connect its campus

passwd = "system",
in Kolkata which is 111ore than 100 kin. VVhich

database= "School")
type of network will be formed?

cursor= mycon.cursor( )
Sol :
d b = cursor .execute

(i) ("CREATE TABLE Student (

Roll No Int( 5) Primary key,

Commerce Block FirstName varchar(30) NOT NULL,

LastName varchar(30),

Address varchar(50),

ContactNo varchar(20)
Office
Marks Float,
Block Science Block
Course char(20),

Rank char(lO) check (Rank IN('Good'

(ii) The most suitable place to house the server , 'Best', 'Bad', 'Worst', 'Average'))))

is Science Block as it has 111axi111un1 munber mycon.close ( )

of computers. Thus, reducing the cabling cost or

and increases efficiency of network. (a) Differentiate between a logical error and

(iii) (b) Switch is the device to be installed in each syntax error. Also, give suitable examples of

of the blocks to connect all the computers. each in Python.

(iv) Star topology, as it is the best in efficiency. (b) What is the use of fetchone() method? Write

(v) vVAN (Wide Area Net,vork) will be formed. an example code to fetch a single record from

a database.
32. (a) Underline the syntax errors in the following
Note:
program
Database : PythonDB
x = int ( i n p u t ( " E n t e r first number:))
Table : Student
y = i n t ( i n p u t ( " E n t e r second n u m b e r : " ) )
Host : localhost
z = int(input("Enter third n u mb e r : " )
UsedlD : root
a = x+ b+ z
Password : arihant
print ("Result = ", b)

(b) Write the code to create the following table Sol :

Student with the following fields (a) Differences between logical error and syntax

RollNo error are a.s follows:

First.Name
Logical Error Syntax Error
Last Name

Address

ContactNo It occurs because of It occurs when

Marks wrong implementation statements are wrongly

Course of logic. written violating rules

Rank of the programnnng

In the table, Rank should be Good, Best, language.

Bad, Worst, Average.


With logical errors, the vVith syntax errors ,

. .
Sol: code IS syntactically the code IS not

correct and compiler syntactically correct


(a)
will not show any error and compiler will show
x = int(input("Enter first number:"))
message. the error messages.
y = int ( i n p u t ( " E n t e r second n u m b e r : " ) )

z - int ( i n p u t ( " E n t e r third number


Page 8 Sample Paper 1 Computer Science Class 12

wl = csv.writer(f2)
It produces the output, It does not produce
for row in rl :
but undesired. any output.
wl.writerow(row)

e.g. in place of e.g. in place of fl.close()

- a if by ( a = = b); if by mistake
(c -
* b); f2.close()

mistake ( a = = b); is wri tte n, it def convertcsv() ·

(c = a + b); is writte n, will be a syntax error. fl - open ( " o l d . c s v " , 'r')

it will be a logical f2 - open("converted.csv", 'w'


'
error. newline= "\n")

(b) fetchone() returns the next row from the rl - csv.reader(fl, delimiter=

result set as tuple. If there are no more rows " : " )

to retrieve, None is returned. wl = csv.writer(f2, delimiter=

e.g. To fetch only one record " ; " )

import mysql.connector for row in rl:

c o n = mysql.connector.connect wl.writerow(row)

(host= "localhost", fl.close()

u s e r = "root", f 2 . close ( )

passwd = "arihant",database addcsv I )

- "PythonDB") convertcsv ( )

cursor= con.cursor() or

try: CSV files are opened with which argument

cursor.execute("Select Name, to suppress EOL translation. Write a python

RollNo, Address, Percentage from program to perform the following using functions

Student") as follows :

display= cursor.fetchone() (a) copytocsv() :

print(display) A CSV file "marks.csv'' has name, class and

except: marks separated by comma. Write the Python

con.rollback() function to copy only the name and class to

c o n . close ( ) another CSV file "class.csv".

(b) copyselected() :
33. Which module is used to operate on CSV file?
The CSV file "marks.csv" which has name,
Write a python program with following functions
class and marks separated by comma. Write

the Python function to copy only rows of


(a) addcsv():
students of class 2 to another CSV file "class.
File old.csv has come from branch in Pune

and it needs to be added to file "updated.

Sol :
csv" which has data for all branches. Write

the code in the function to perform the same. newlinee ' ,

(b) convertcsv() : Program:

A file old. csv has come with separator ' : " but import csv

your system can only read ' ; ' Write a program def copytocsv() ·

to convert to "converted.csv" file. Write the file= open('class.csv', 'w',

function to change the separator of the file. newline="")

writer= csv.writer(file)
Sol :
with open ( ' m a r k s . c s v ' ) as csvfile:
To read and write in CSV files we need to import
data= csv.reader(csvfile)
csv module.
for row in data:
Program:
writer.writeraw(row[O],
import csv
row [ 1 J J )

def addcsv() ·
file. close ( )
fl - open("old.csv", 'r')
def copyselected() ·
f2 - open("updated.csv", 'a',
fi l e = open ( ' c l a s s . c s v ' , 'w'
'
newline= "\n")
newline= "\n")
rl - csv.reader(fl)
wl - csv.writer(file)
Page 9 Sample Paper 1 Computer Science Class 12

with open ( ' m a r k s . c s v ' ) as csvfile: p r i n t (fileda ta I

data = csv. reader (csvfile) da ta=fileda t a . s p l i t ( ' ' )

for row in data: for in data : #Blank!

if row [ 1 ] == '2' : if words[-!] in "aeiou" and . . . in

writer.writerow(row) "AEIOU": # Blank2

file. c l o s e ( I print( ) # Blank3

copytocsv ( I f .close ( I

copyselected ( I (i) '�'rite the missing code for Blankl.

(ii) Write the missing code for Blank2.

(iii) Write the missing code for Blank3.

Section E Sol :

(i) words
34. Consider the following table Person
(ii) words[D]

p Id LastNa,nc First Name Address City (iii) words


-

1 Hansen Ola 'I'nuotcivu Sandnes

10

2 Svcndson Tove Borgvn 23 Sandnes

END
3 Pettersen Keri Storgt 20 Stavanger

4 Nilsen Johan Bakken 2 Stavanger

(i) What should be the constraint(s) of the P_Id

column?

(ii) If 3 columns are added to the table , what will

be its degree?

(iii) Write statements to :

(a) Display the Unique Cities.

(b) Display Firstnames of people who do not

have a address.

or (Option for part (iii} only}

Write appropriate data types to store the

following :

(a) Amounts carrying values with decimal.

(b) Joining elates.

Sol :

(i} Primary key

(ii) 8, There are 5 columns + 3 = 8 columns.

Degree is number of columns.

(iii} (a) SELECT DISTINCT City FROM

Person;

(b) SELECT FirstName FROM Person

WHERE address IS NULL;

or

(a) floatydecimal/double

(b} date/ datetime

35. The code given below reads a text file and displays

those words that begin with an uppercase vowel

and end with a lowercase vowel . Some of the codes

are missing .Write codes to fill up the blanks.

f=open("emp.txt")

fileda t.a=f . read ( )

count=O

You might also like