Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

12COM02MS

KENDRIYA VIDYALAYA SANGATHAN, CHENNAI REGION


PRE-BOARD EXAMINATION – II 2023-24
Class: XII Computer Science (083) Theory
Marking Scheme
SECTION-A
1 State True or False 1
In Dynamic Typing the datatype attached with the variable can change during the
program run.
True
2 Which of the following is/are invalid identifier(s) in Python? 1
(a) _number (b) None (c)123int (d)decimal
3 What will be the output of the following Python code: 1
try:
a = 10
b=0
c = a/b
print ("a/b =", c)
except Exception as error:
print(error)
else:
print ("No Error")
a)0 b)No Error c) Value Error d) division by zero
4 Expand the following terms: 1
(i) PPP :Point to point Protocol (ii) VoIP: Voice over internet protocol
5 Give the output of code snippet given below: 1
L=[1,2,3]
L2=L.append(4)
print (L2)
a) [1,2,3] b) None c) TypeError d) [1,2,3,4]
6 What is the primary function of a router in a network? 1
a) Forwards data packets between devices within the same network
b) Connects devices within the same local area network (LAN)
c) Connects different networks and makes decisions based on IP addresses
d) Amplifies and regenerates signals in a network
7 Given the below code snippet, which of the following options would create a 1
variable called final_string that is assigned to the word “yelling”?
string1= "yellow"
string2= "screaming"
(a) final_string = string1[:4] + string2[6:]
(b) final_string = string1[:3] + string2[6:]
(c) final_string = string1[:3] + string2[6: -1]

Page 1 of 14
(d) final_string = string1[:4]. append(string2[-3:])
8 Network in which every computer is capable of playing the role of a client, or a 1
server or both at same time is called
a) local area network b) peer-to-peer network
c) dedicated server network d) wide area network
9 Which of the following statements is TRUE about keys in a relational database? 1
a) A candidate key is not eligible to become a primary key.
b) A primary key uniquely identifies the attributes in a relation.
c) A candidate key that is not a primary key is a foreign key.
d)A foreign key is an attribute whose value is derived from the primary key
of another relation
10 What is the purpose of the SQL JOIN clause? 1
a) To create a new table
b) To combine rows from two or more tables based on a related column
c) To delete records from a table
d) To update data in a table
11 Study the following program and select the possible output(s) from the options 1
(i) to (iv) following it.
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 : 3
½ MARK FOR EACH OPTION
12 Write the output:- 1
myTuple = ("John", "Peter", "Vicky")
x = "#".join(myTuple)
print(x)
a) #John#Peter#Vicky b) John#Peter#Vicky
c) John#Peter#Vicky# d) #John#Peter#Vicky#
13 Given the following dictionaries 1
dict_fruit={"Kiwi":"Brown", "Cherry":"Red"}
dict_vegetable={"Tomato":"Red", "Brinjal":"Purple"}
Which statement will merge the contents of both dictionaries?
a) dict_fruit.update(dict_vegetable) b) dict_fruit + dict_vegetable
c) dict_fruit.add(dict_vegetable) d) dict_fruit.merge(dict_vegetable)
14 Which of the following file opening mode in Python, generates anerror if the file 1
does not exist?
a) a b)r c) w d) w+
15 If a function is defined by the line "defcalculate(p, q=100, r=10):", which of the 1
following istrue?
a) p is an optional parameter
b)q and r are optional parameters
c) q will always have value 100 in the function
d) the above line will cause a syntax error
16 Which of the following SQL statements is used to open a database named 1

Page 2 of 14
“SCHOOL”?
a) CREATE DATABASE SCHOOL;
b) USE DATABASE SCHOOL;
c) USE SCHOOL;
d) SHOW DATABASE SCHOOL;
Q17 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 for A
(c) A is True but R is False
(d) A is false but R is True
17 Assertion (A): Python's pass statement is used for documentation purposes. 1
Reason (R): The pass statement does nothing and acts as a placeholder.
ANS: d
18 Assertion (A): In Python, a variable defined inside a function is local to that 1
function.
Reason (R): Local variables can be accessed outside the function they are
defined in.
ANS: C
SECTION-B
19 a=int{input("ENTER FIRST NUMBER")} 2
b=int(input("ENTER SECOND NUMBER"))
c=int(input("ENTER THIRD NUMBER"))
if a>b and a>c
print("A IS GREATER")
if b>a and b>c:
Print(" B IS GREATER")
if c>a and c>b:
print(C IS GREATER)
ANSWER:
a=int(input("ENTER FIRST NUMBER"))
b=int(input("ENTER SECOND NUMBER"))
c=int(input("ENTER THIRD NUMBER"))
if a>b and a>c:
print("A IS GREATER")
if b>a and b>c:
print(" B IS GREATER")
if c>a and c>b:
print("C IS GREATER")
½ mark for each correction
20 Differentiate between server side script and client side script. Write one example 2
of each.
Ans: client side scripting runs code on your browser while server-side scripting
runs on the back-end server.
Server Side Script: ASP, JSP
Client Side Script: JavaScript, VBScript
Or
Page 3 of 14
What are protocols? Name protocols for sending and receiving e-mail.
Ans: In networking, a protocol is a standardized set of rules for formatting and
processing data. Protocols enable computers to communicate with one another.
Protocol for sending e-mail: SMTP
Protocol for receiving e-mail: POP3
21 Differentiate between Alter and Update. 2
Ans:
S.NO. ALTER Command UPDATE Command
ALTER command is Data UPDATE Command is a Data
1
Definition Language (DDL). Manipulation Language (DML).
Alter command will perform
Update command will perform on
2 the action on structure level
the data level.
and not on the data level.
ALTER Command is used to
UPDATE Command is used to
add, delete, and modify the
3 update existing records in a
attributes of the relations
database.
(tables) in the database.
ALTER Command by default
UPDATE Command sets specified
4 initializes values of all the
values in the command to the tuples.
tuple as NULL.
1 mark each for any two differences
Or,
Differentiate between where and having
SR.N
O. WHERE Clause HAVING Clause
WHERE Clause is used to
HAVING Clause is used to filter
filter the records from the table
1. record from the groups based on
based on the specified
the specified condition.
condition.
WHERE Clause can be used HAVING Clause cannot be used
2.
without GROUP BY Clause without GROUP BY Clause
WHERE Clause implements in HAVING Clause implements in
3.
row operations column operation
WHERE Clause cannot contain HAVING Clause can contain
4.
aggregate function aggregate function
1 mark each for any two differences
22 a) Given is a Python string declaration: 2
str="CBSE Examination@2024"
Write the output of: print(str[-1:-15:-2])
Ans: 40@otnm
(b) Write the output of the code given below:
d = {"name": "Akash", "age": 16}
d['age'] = 27
d['city'] = "New Delhi"
print(d.items())
Ans: dict_items([('name', 'Akash'), ('age', 27), ('city', 'New Delhi')])

Page 4 of 14
23 Write the output of the following code: 2
a=20
def calling(x):
global a
if a%3!=0:
x+=a
else :
x-=a
return(x)
print (calling(45),end="&&")
print (calling(35),end="@@")
Ans:
65&&
55@@
½ mark for 65, ½ mark for &&, ½ mark for 55, ½ mark for @@
Reduce ½ mark if line not changed.
24 Write a suitable Python statement for each of the following tasksusing built-in 2
functions/methods only:
a) To delete an element Mumbai:50 from Dictionary D.
Ans: del(D["Mumbai"]) or D.pop("Mumbai”)
b) To display words in a string S in the form of a list
Ans: print(S.split())
OR
Write a Python Program to display alternate characters of a stringmy_str.
For example, if my_str = "Computer Science"
The output should be Cmuecec
Ans: print(my_str[::2])
25 Write a Python Program containing a function FindWord(STRING,SEARCH), 2
that accepts two arguments : STRING and SEARCH, andprints the count of
occurrence of SEARCH in STRING. Writeappropriate statements to call the
function.
For example, if STRING = "Learning history helps to know abouthistory with
interest in history" and SEARCH = 'history', the functionshould display
The word history occurs 3 times.
Ans:
defFindWord(STRING,SEARCH):
return (STRING.split() . count (SEARCH) )
str = input('Enter String : ')
word = input('Enter word to search : ')
print('The word', word, 'occurs', FindWord(str,word), 'times')

Page 5 of 14
SECTION-C
26 a) Differentiate between Natural join and Equi join. 1+
b) Table : Employee 2
EmployeeId Name Sales JobId
E1 SumitSinha 110000 102
E2 Vijay SinghTomar 130000 101
E3 Ajay Rajpal 140000 103
E4 Mohit Kumar 125000 102
E5 Sailja Singh 145000 103
Table: Job
JobId JobTitle Salary
101 President 200000
102 Vice President 125000
103 Administrator Assistant 80000
104 Accounting Manager 70000
105 Accountant 65000
106 Sales Manager 80000
Give the output of following SQL statement:
(i) Select Name, JobTitle, Sales from Employee, Job
where Employee.JobId=Job.JobId and JobId in (101,102)
(ii) Select JobId, count(*) from Employee group by JobId
Ans:
a) Equi Join displays the common column twice ,where as the Natural join
displays the common column only once in the Join query.
(b) (i)
Name JobTitle Sales
Vijay Singh Tomar President 130000
SumitSinha Vice President 110000
Mohit Kumar Vice President 125000
ii.
JobId Count(*)
101 1
102 2
103 2
27 Write a function in python named SwapHalfList(Array), which accepts a list 3
Array of numbers and swaps the elements of 1st Half of the list with the 2nd
Half of the list, ONLY if the sum of 1st Half is greater than 2nd Half of the list.
Sample Input Data of the list
Array= [ 100, 200, 300, 40, 50, 60],
Output Array = [40, 50, 60, 100, 200, 300]
Ans: defSwapHalfList(Array):
s1=s2=0
L=len(Array)
for i in range(0,L//2):
s1+=Array[i]

Page 6 of 14
for i in range(L//2, L):
s2+=Array[i]
if s1>s2:
for i in range(0,L//2):
Array[i],Array[i+L//2]=Array[i+L//2],Array[i]
L=[6,5,4,1,2,3]
SwapHalfList(L)
print(L)
[1/2 mark for writing correct function header. 2 marks for correct logic and 1/2
mark for calling the function. Any other logic producing the same result is
accepted]
28 Write a function ETCount() in Python, which should read eachcharacter of a text 3
file “TESTFILE.TXT” and then count and displaythe count of occurrence of
alphabets E and T individually (includingsmall cases e and t too).
Or,
Write a method/function DISPLAYWORDS() in python to read lines from a text
file POEM.TXT, and display those words, which are less than 4 characters.
Ans:
defETCount() :
file = open ('TESTFILE.TXT', 'r')
lines = file.readlines()
countE=0
countT=0
for w in lines :
for ch in w:
if ch in 'Ee':
countE = countE + 1
elifch in 'Tt':
countT=countT + 1
print ("The number of E or e : ", countE)
print ("The number of T or t : ", countT)
file.close()
(½ mark for correctly opening and closing the file
½ for readlines()
½ mark for correct loops
½ for correct if statement
½ mark for correctly incrementing counts
½ mark for displaying the correct output)
Note: Any other relevant and correct code may be marked

Or
def DISPLAYWORDS():
file=open('POEM.txt','r')
line = file.read()
word = line.split()
for w in word:

Page 7 of 14
if len(w)<4:
print( w)
file.close()
(½ Mark for opening the file)
(½ Mark each for reading line and splitting)
(½ Mark each for loop and checking condition)
(½ Mark for printing word)
29 Tulasi creates a table RESULT with a set of records to maintain themarks 3
secured by students in Term1, Term2, and their divisions.After the creation of
the table, he entered data of 7 students in thetable.
ADNO ROLLNO SNAME TERM1 TERM2 DIVISION
123 101 KARAN 366 410 I
245 102 NAMAN 300 350 I
128 103 ISHA 400 410 I
129 104 RENU 350 357 I
234 105 ARPIT 100 75 IV
187 106 SABINA 100 205 II
181 107 NEELAM 470 450 I
Based on the data given above answer the following questions:
a) Identify the columns which can be considered as candidate keys?
b) If one more columns are added and 3 rows are deleted from the table
result, what will be the new degree and cardinality of the above table?
c) Write a statement to increase the TERM2 marks by 3% for the students
securing marks between 70 to 100.
Ans:
a) ADNO, ROLLNO
b) Degree:7, Cardinality: 4
c) Update RESULT Set TERM2=TERM2+.03*TERM2
30 A nested list contains the data of visitors in a museum. Each of the inner 3
listscontainsthe following data of a visitor:
[V_no (int), Date (string), Name (string), Gender (String M/F), Age (int)]
Write the following user defined functions to perform given operations on the
stacknamed "status":
(i) Push_element(Visitors) - To Push an object containing Gender of visitor who
are in the age range of 15 to 20.
(ii) Pop_element() - To Pop the objects from the stack and count the display the
number of Male and Female entries in the stack. Also, display “Done” whenthere
are no elements in the stack.
For example: If the list Visitors contains:
[['305', "10/11/2022", “Geeta”,"F”, 35],
['306', "10/11/2022", “Arham”,"M”, 15],
['307', "11/11/2022", “David”,"M”, 18],
['308', "11/11/2022", “Madhuri”,"F”, 17],
['309', "11/11/2022", “Sikandar”,"M”, 13]]
The stack should contain
F

Page 8 of 14
M
M
The output should be:
Done
Female: 1
Male: 2
ANS:
visitors=[['305', '10/11/2022', 'Geeta','F', 15],['306', '10/11/2022', 'Arham','M',
15],['307', "11/11/2022", 'David','M', 18],['308', "11/11/2022", 'Madhuri','F', 17]]
status=[]
defPush_Element(visitors):
global status
m_c=0
f_c=0
for i in visitors:
if i[4]>=15 and i[4]<=20:
status.append(i[3])
if i[3]=='M':
m_c+=1
ifi[3]=='F':
f_c+=1
print("Males:",m_c)
print("FeMales:",f_c)
defPop_Element():
global status
if status!=[]:
return status.pop()
else:
return "Done"
Push_Element(visitors)
for i in range(len(status)+1):
print(Pop_Element())
SECTION-D
31 A csv file “Book.csv” has structure [BookNo, Book_Name, Author, Price]. 2+
a. Write a user defined function CreateFile() to input data for a record and add to 2
Book.csv .
b. Write a function CountRec(Author) in Python which accepts the Author name
as parameter and count and return number of books by the given Author are
stored in the file “Book.csv”
Ans:
a. import csv
defCreateFile():
print("Enter Values")
B=input("Book No: ")
N=input("Book Name: ")
A=input("Author Name: ")

Page 9 of 14
P=input("Price: ")
r=[B,N,A,P]
file=open("Book.csv","w")
writer=csv.writer(file)
writer.writerow(r)
file.close()
b. defCountRec(Author):
file=open("Book.csv")
count=0
reader=csv.reader(file)
for rec in reader:
if rec[2]==Author:
count+=1
print("The Number of Books: ",count)
file.close()
32 Write SQL queries for (a) to (d)on the basis of tables given below 4
Table : TRAINS
TNO TNAME START END
11096 Ahimsa Express Pune Junction Ahmedabad Junction
12015 Ajmer Shatabdi New Delhi Ajmer Junction
1651 Pune Hbj Special Pune Junction Habibganj
13005 Amritsar Mail Howrah Junction Amritsar Junction
12030 SwarnaShatabdi Amritsar Junction New Delhi

Table : PASSENGERS
PNR TNO PNAME GENDER AGE TRAVELDATE
P001 13005 R N AGRAWAL MALE 45 2018-12-25
P002 12015 P TIWARY MALE 28 2018-11-10
P003 12015 S TIWARY FEMALE 22 2018-11-10
P004 12030 S K SAXENA MALE 42 2018-10-12
P005 12030 S SAXENA FEMALE 35 2018-10-12

a) To display total number of MALE and FEMALE Passengers


b) To display details of all Trains which Start from Pune Junction
c) To display details of all Passengers travelling in Trains whose TNO is 12030
d) To display the PNR, PNAME, GENDER and AGE of all Passengers whose
AGE is above 50
ANS:
a) SELECT GENDER,COUNT(*) FROM PASSENGERS GROUP BY
GENDER
b) SELECT * FROM TRAINS WHERE START=' Pune Junction '
c) SELECT * FROM PASSENGERS WHERE TNO=12030
d) SELECT PNR,PNAME,GENDER,AGE FROM PASSENGER WHERE
AGE<50
SECTION-E
33 Piccadily Design and Training Institute is setting up its centre in Jodhpur with 5
Page 10 of 14
four specialised units for Design, Media, HR and Training in separate buildings.
The physical distances between these units and the number of computers to be
installed in these units are given as follows.
Shortest distances between various locations in metres :
Design Unit to Media Unit 60
Design Unit to HR Unit 40
Design Unit to Training Unit 60
Media Unit to Training Unit 100
Media Unit to HR Unit 50
Training Unit to HR Unit 60

Number of computers installed at various locations are as follows :


Design Unit 40
Media Unit 50
HR Unit 110
Training Unit 40

You as a network expert, have to answer the queries as raised by the


administrator as given in (a) to (e).
a) Suggest by drawing the cable layout for effective network connectivity.
b) Suggest the most suitable location to install the main server.
c) Suggest the devices to be installed in each of these buildings for
connecting computers installed within each of the units out of the
following :
Modem, Switch, Gateway, Router
d) Suggest an efficient as well as economic wired medium to be used within
each unit for connecting computer systems out of the following network
cable :
Co-axial Cable, Ethernet Cable, Single Pair Telephone Cable
e) Is there a requirement of a repeater in the given cable layout? Why/Why
not?
ANS:
a) Any topology
b) HR unit, as it has maximum number of computers
c) Switch

Page 11 of 14
d) Ethernet Cable
e) Not required as distances are less than 70m.
34 a) Write any two difference between text file and binary file. 2+
b)Mayur is a student, who has a binary file called STUDENT.DAT containing 3
information- sid, name and age of each student. [sid, name , age]
Write the user defined function Get_Stud() to display the name and age of those
student who have a age greater than 18 year. In case there is no student having
age >18 the function displays message “There is no student who is greater than
18 year”

(i)
s. no. Text File Binary File
1 Contains human-readable Contains a sequence of bytes that
characters and typically stores can represent any type of data,
plain text. Each character is including text, images, audio, and
encoded using a character program executables.
encoding like ASCII or
Unicode.
2 Organized as a sequence of Can have a complex structure
lines, with each line containing depending on the type of data it
a series of characters. Text files represents. It may include headers,
are often structured with a footers, and data structures specific
newline character ("\n") to the application or file format.
separating lines.
3. Readable by humans using a Not easily readable by humans
simple text editor. The content since the data is encoded in a
is easily interpreted, making it binary format. Specialized software
convenient for configuration or tools are often required to
files, scripts, and other human- interpret and manipulate the data.
readable data.

(1 mark for any difference between text file and binary file)
(ii)import pickle
defGet_Stud():
Total = 0
Count_rec = 0
Count_age = 0
with open(“ STUDENT.DAT”, “ rb”) as F:
while True:
try:
R=pickle.load(f)
Count_rec = Count_rec+1
Total = Total+R[2]
if R[2] > 18:
print (R[1],“is of Age :”,R[2])

Page 12 of 14
Count_age + = 1
except:
break
if Count_age = =0 :
print(“There is no student who is greater than 18 year”)

Get_Stud()
35 a) What is the difference between a Candidate Key and an Alternate Key. 1+
b) Manoj has created a table named TRAVELS in MySQL: 4
Tour_ID – string
Destination – String
Geo_Cond– String
Distance – integer (In KM)
Note the following to establish connectivity between Python and MYSQL:
 Username is root
 Password is kvs
 The table TRAVELS exists in a MYSQL database named TOUR.
The details Tour_ID, Destination, Geo_Cond and Distance are to be accepted
from the user.
Manoj wants to display All Records of TRAVELS relation whose Geographical
condition is hilly area and distance less than 1000 KM. Help Manoj to write
program in python.
Or,
(i) Write one point of difference between PRIMARY KEY and UNIQUE KEY
in SQL.
(ii) Aarya has created a table named Emp in MySQL:
EmpNo – integer
EmpName – string
Age– integer
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
 Username - root
 Password - kvs
 Host - localhost
 The Emp table exists in a MYSQL database named company.
 The details of Emp table (EmpNo, EmpName, Age and Salary)
Aarya wants to display All Records of Emp relation whose age is greater than
55. Help Aarya to write program in python.
Ans:
(i)Any one difference:
CANDIDATE KEY ALTERNATE KEY

All attributes in a relation thathave All the leftover candidate keysafter


potential tobecome a Primary key selecting the primary key

(ii)

Page 13 of 14
import mysql.connector as BD
defEmp_Database():
con=BD.connect(host="localhost", user="root",
password="kvs",database="TOUR")
BDcursor=con.cursor()
print("Travels at Hilly Area and the distance more than 1000 KM.:")
BDcursor.execute("select * from TRAVELS WHERE Geo_Cond = 'hilly
area' AND Distance<1000;")
TravelRec= BDcursor.fetchall()
for rec in TravelRec:
print(rec)

Or

(i)Any one difference:

PRIMARY KEY UNIQUE KEY


There can be only one primary There can be more than one unique
key in a table keys in a table

The primary key cannot have null Unique can have null values
values

(ii)
import mysql.connector as cnt
defEmp_Database():
con=cnt.connect(host="localhost", user="root", password="kvs",
database="company")
mycursor= con.cursor()
print("Display Employee whose age is more than 55 years:")
mycursor.execute("select * from Emp where age>55”)
EmpRec= mycursor.fetchall()
for rec in EmpRec:
print(rec)

END OF THE PAPER. BEST WISHES

Page 14 of 14

You might also like