You are on page 1of 16

के न्द्रीय विद्यालय संगठन, कोलकाता संभाग

KENDRIYA VIDYALAYA SANGATHAN, KOLKATA REGION


वितीय प्री-बोर्ड परीक्षा / SECOND PRE-BOARD EXAM. – 2022-23
कक्षा / CLASS – XII अविकतम अकं /MAX. MARKS – 70
विषय/SUB. – COMPUTER SCIENCE (083) समय/TIME – 03 घंटे/Hours

MARKING SCHEME
SECTION - A
1 State True or False: “Keywords cannot be used as identifiers in Python.” 1
Ans: True
2 Which of the following is an invalid identifier in Python? 1
(a) false (b) False (c)true (d) IF
Ans: (b) False
3 Given the following dictionaries 1
dict_exam={"Exam":"AISSCE", "Year":2023,"Total":500,
"Pass_Marks":165}

which of the following command will give the below output:


[“Exam”, “Year” , “ Total” , "Pass_Marks" ]

a. dict_exam.itmes()
b. exam.values()
c. dict_exam.keys()
d. dict_exam.items()

Ans : ( c) dict_exam.keys()
4 What will be the output of the following statement: 1 (1)
print(3-10**2+99/11)
(a) 80 (b) - 81 (c) -88 (d) - 81.0
Ans: (c) -88
5 What will be the output of the following code? 1
Str1="My name is digital"
Str2=Str1[3:7]
strlen = len(Str2)
print(strlen)
(a) 4 (b) 14 (c) 24 (d) 34
Ans: (a) 4
6 In which of the following only write mode is allowed ? 1
(a) ab (b) r+ (c) w+ (d) None of the above
Ans : (a) ab
7 Fill in the blank: 1
______ keyword is used to display non-repeated values in MySQL.
(a) Unique (b) Remove (c) Distinct (d) All
Ans: (c) Distinct
8 Which of the following command is used for modifying a record from a table ? 1
(a) ALTER (b)UPDATE
KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 1
(c) CHANGE (d) MODIFY
Ans : (b) UPDATE

9 Which of the following statement(s) would give an error after executing the following 1
code?
tup = (20,30,40,50,80,79)
print(tup) #Statement 1
print(tup[3]+50) #Statement 2
print(max(tup)) #Statement 3
tup[4]=80 #Statement 4
(a) Statement 1 (b) Statement 2 (c) Statement 3 (d) Statement 4
Ans: (d) Statement 4
10 Fill in the blank: 1
Cartesian product of two table will contain ______ of rows and ________
of column.
(a) Sum , Product
(b) Product , Sum
(c) Difference , Product
(d) Sum , Sum
Ans : b) Product , Sum

11 Which of the following is the correct syntax of file object ‘fobj’ to write sequence 1
data type using writelines() function? (1)
(a) file.writelines(sequence)
(b) fobj.writelines()
(c) fobj.writelines(sequence)
(d) fobj.writeline()
Ans: (c) fobj.writelines(sequence)
12 In MySQL, what is the use of column alias ? 1
(a) Giving a new name to the output column (b) Renaming a column
(c) Renaming a row (d) None of these
Ans: (a) Giving a new name to the output column
13 Fill in the blank: 1
is a communication protocol used by email clients to retrieve email messages
from mail servers
(a) PPP (b) SMTP (c) VoIP (d)POP
Ans : d ) POP
14 What will the following expression is an iterable in Python ? 1
(a) int (b) string (c) boolean (d) None of these
Ans: (b) string
15 Which of the following function will ignore NULL value in MySQL ? 1
(a) count(<attribute>) (b) sum() (c) count(*) (d) None of these
Ans: (c)count(*)
16 which of the following is used for checking successful connection of 1
database with connected object
a) is_connected () b) is_cursor ()
KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 2
c)if_fetch() d) is_connect()
Ans: (a) ) is_connected ()
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): Function can take input values as parameters, execute them and 1
return output (if required) to the calling function with a return statement. (1)
Reason (R): A function in Python can return multiple values in the form of
tuple.
Ans: (b)
18 Assertion (A): Modules provide reusability of code. 1 (1)
Reason (R): We can define a module and import it for reusing without copying their
definitions into different programs.
Ans: (a)

SECTION - B

19 Kumar has written a code to input a number and check whether it is composite or 2
not. His code is having errors. Rewrite the correct code and underline the corrections
made.
def prime():
n=int(input("Enter number to check :: ")
for i in range (2, n//2):
if n%i=0:
print("Number is a composite number\n")
break
else:
print("Number is prime \n’)
Ans:
def prime():
n=int(input("Enter number to check :: ") )
for i in range (2, n//2):
if n%i==0:
print("Number is a composite number\n")
break
else:
print("Number is prime \n”)
20 What is use of MODEM and Repeater? 2
Ans:
MODEM – coverts analog signal to digital signal and vice-versa.
Repeater – Regenerates signals
OR

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 3


Write two points of difference between Star topology and Ring topology.
Ans:
Any difference between star and bus topology.
21 (a) mySubject = "Computer Science" 1
Write the output of: print(mySubject[-100:8:])
Ans: Computer

(b) Write the output of the code given below:


a=[10,20,30,40,50,60,70]
a.insert(-1,-2)
print(a) 1
Ans: [10, 20, 30, 40, 50, 60, -2, 70]
22 Explain the use of ‘primary Key’ in a Relational Database Management System. Give 2
example to support your answer.
Ans:
Primary key is used for identification of the tuples. Related example(table) showing
primary key.
23 (a) Write the full forms of the following: 1
(i) GSM (ii) TCP / IP +
Ans: 1
(i) GSM – Global System for Mobile communication
(ii) TCP / IP – Transmission Control Protocol / Internet Protocol

(b) Mention any two features of XML??


Ans:
i) It is used for creating user defined tags.
ii) It is case sensitive
24 Write the output of the given code: 2
def Display(l):
l2=[]
for n in l:
if n % 2 == 0:
l2.append (n)
return l2
print(Display([100, 228, 333, 432, 509, 60, 787, 800, 967]))

Ans: [100, 228, 432, 60, 800]

OR
Write the output of the given code:
t1=(10,20,"book",30,9.5,"item",[12,13],(3,4),30,5,30)
print(t1.index(20))

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 4


print(t1.index(30))
print(t1.count(30))
print(t1[-8:-4])
Ans:
1
3
3
(30, 9.5, 'item', [12, 13])
25 Explain equi join using an example. 2
Ans:
EQUI JOIN creates a JOIN for equality or matching column(s) values of the
relative tables.
E.g.:
SELECT student.name, student.id, record.class, record.city
FROM student, record
WHERE student.city = record.city;

OR
Write two examples for each of following
DDL , DML
Ans:
DDL : ALTER, DROP
DML: INSERT, UPDATE

SECTION-C

26 (a) 1
Consider the following tables – CARDEN and CUSTOMER: +
2

What will be the output of the following statement?


SELECT count(*) FROM CARDEN, CUSTOMER;
Ans: 16

(b)
Write the output of the queries (i) to (iv) based on the table, STOCK given below:

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 5


(i) SELECT Dcode, MAX(UnitPrice) FROM STOCK GROUP BY Dcode;
(ii) SELECT COUNT(DISTINCT Dcode) FROM STOCK;
(iii) SELECT Qty*UnitPrice FROM STOCK WHERE ItemNo=5006;
(iv) SELECT MIN(StockDate) FROM STOCK;
Ans:
(i) Dcode MAX(UnitPrice)
102 20
101 22
103 8

(ii) COUNT(DISTINCT Dcode)


3
(iii) Qty*UnitPrice
4400
(iv) MIN(StockDate)
01-01-2009
27 Write a user-defined function Count_H_T() in Python that displays the number of 3
lines starting with ‘H’ ot ‘T’ in the file “Poem.txt”.
Example, if the file contains: (3)
Here we go round the mulberry bush,
The mulberry bush,
The mulberry bush.
Here we go round the mulberry bush
On a cold and frosty morning.
The line count should be 4.
Ans:
def Count_H_T():
c=0
f=open("poem.txt")
d=f.readlines()

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 6


for i in d:
if i[0] in 'HhTt':
c+=1
print(c)
OR

Write a method COUNTWORD() in Python to read words from text file 'TESTFILE.TXT’
and count the words which are not starting with any vowel.
Example:
If the file content is as follows:
An apple a day keeps the doctor away.
We all pray for everyone’s safety.
A marked difference will come in our country.
The COUNTWORD() function should display the output as:
No. of words not starting with vowel is 8
Ans:
def COUNTWORD():
c=0
f=open("TESTFILE.TXT")
d=f.read()
w=d.split()
for i in w:
if i[0] not in 'AEIOUaeiou':
c+=1
print("No. of words not starting with vowel is ",c)
28 (a) Write the outputs of the SQL queries (i) to (iv) based on the relations 2
MOBILEMASTER & MOBILESTOCK given below: +
1

(i) SELECT M_Company, M_Name, M_Price,M_Qty FROM MOBILEMASTER


MM,MOBILESTOCK MS, WHERE MM.M_ID= MS.M_ID;
(ii) SELECT MAX(M_Price) FROM MOBILEMASTER WHERE M_Name LIKE "S%";
(iii) SELECT M_Supplier, M_Qty FROM MOBILESTOCK WHERE M_Id ="MB003";

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 7


(iv) SELECT M_Company FROM MOBILEMASTER WHERE M_Price BETWEEN 3000
AND 5000;
Ans:
(i)
M_Id M_Company M_Name M_Price M_Mf_Date M_Qty
MB001 Samsung Galaxy 4500 12-02-2013 300
MB003 Nokia N1100 2250 15-04-2011 250
MB004 Micromax Unite3 4500 17-10-2016 450
MB006 Oppo SelfieEx 8500 21-08-2010 150
(ii)
MAX(M_Price)
7500
(iii)
M_Qty M_Supplier
250 Praveen Gallery
150 The Mobile
(iv)
M_Company
Samsung
Micromax

(a) What is Cardinality of a table ?


Ans: No. of rows in a table.
29 Write a function Join_List() which receives two lists as arguments and creates a third 3
list containing odd elements from 1st list followed by even elements from 2nd list and
returns the third list.
E.g.
Two lists are:
List1 : [11,2,5,7,4,8]
List2:[12,19,20,10,15,18]
Returned List : [11,5,7,12,20,10,18]
Ans:
def Join_List(n1,n2):
l=list()
for i in n1:
if i%2==1:
l.append(i)
for i in n2:
if i%2==0:
l.append(i)
return l

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 8


30 A list contains the following record of a Hostel: 3
[Hostel_No,total_stu,total_rooms]
Write the following user defined functions to perform given operations on the stack
named ‘Hostel’:
(i) Push_element() - To push an object containing Hostel_No and Total Students
along with Total Rooms to the stack.
(ii) Pop_element() - To pop the objects from the stack and display them. Also, display
“Stack Empty” when there are no elements in the stack.
For example:
[1,2000,1000]
[2, 1500,800]
[3,5000,2000]
The output should be:
[1,2000,1000]
[2, 1500,800]
[3,5000,2000]
Stack Empty
Ans:
def Push_element():
Hostel_No=input("Enter hostel number:")
total_stu=int(input("Enter total no. of students :"))
total_rooms=int(input("Enter total no. of rooms :"))
d=[Hostel_No,total_stu,total_rooms]
Hostel.append(d)
def Pop_element():
while len(Hostel)!=0:
d=Hostel.pop()
print(d)
print("Stack Empty")
OR
Write a program to implement a Stack for book_details (book name : book price)
where book name is a key and book price is value. Write a function in Python,
Push(book_details) where book_details is a dictionary containing the details of
books– {book_name : book_price}. The function should push the names of those
books in the stack which have price greater than 500. Also display the count of
books pushed into the stack.
For example: If the dictionary contains the following data:

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 9


books={"Python":560,"Java":450,"MySQL":330,"Web Development":725}
The stack should contain Python and Web Development. The output should be:
The count of books in the stack is 2.
Ans:
s= list()
def Push(book_details):
for i in book_details:
if book_details[i]>500:
s.append(i)
print("The count of books in the stack is",len(s))

SECTION - D

31 5

(i) What will be the most appropriate block, where ABC should plan to install
their server?
(ii) Which type of topology is best suited for above network
(iii) What will be the best possible connectivity you will suggest to connect the
new setup of offices in Chennai with its London based office?
(iv) Which device will be suggested by you to connect each computer in each of
the buildings?
(v) The company once internet accessibility in all the blocks. What would the
suitable and cost effective technology for that ?
Ans:
(i) Finance block
(ii) LAN
(iii) Satellite
(iv) Hub / Switch
(v) Broadband
32 2
+
3

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 10


(a) Write the output of the code given below:
p=8
def sum(q,r=3):
global p
p=r+q**2
print(p)

a=20
b=8
sum(a,b)
res=sum(r=7,q=1)
print(res)

Ans: 408 8 None


1 Marks for Writing 408 and 8
1 Mark for writing None

(b) The code given below inserts the following record in the table Fun_City:
Ticket_Id – integer
Name – string
Ticket_Price – integer
No_Of_Tickets – integer
Total_Amount – integer
Note the following to establish connectivity between Python and MySQL:
• Username is root
• Password is Ticket
• The table exists in a MySQL database named Amusement.
• The details (Ticket_Id, Name, Ticket_Price, No_of_Tickets) are to be
accepted by the user. Write the following missing statements to complete
the code:
Statement 1 – To form the cursor object
Statement 2 – Write a command to execute the command
Statement 3 – Write a command to save data permanently in the database.

import mysql.connector as mysql


con=mysql.connect(host="localhost",user="root", password="Ticket",
database="Amusement")
mycursor= …………………………………………. #Statement 1
Ticket_No=int(input("Enter Ticket Number :: "))
Name=input("Enter Name :: ")
Ticket_Price= input("Enter Ticket Price :: ")
No_Of_Tickets=int(input("Enter No of tickets :: "))
Total_Amount= Ticket_Price * No_Of_Tickets
query="Insert into Fun_City values({},'{}',{},{})".format(Ticket_No, Name,
Ticket_Price, No_Of_Tickets, Total_Amount)
…………………………………………………. #Statement 2

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 11


………………………………………………….. #Statement 3
print("Data Added successfully")

Ans:
Statement 1 – mycursor=con.cursor()
Statement 2 – mycursor.execute(query)
Statement 3 – mycursor.execute(“Commit”)

OR

(a) Predict the output of the code given below:


s="Welcome23BYE22"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'*'
print(m)

Ans: wELCcME**bye**

(b) The code given below reads the following record from the table
named Employee and displays only those records who have a Salary greater
than 75000:
• EmpNo – integer
• EmpName – string
• Designation – string
• Salary – integer
Note the following to establish connectivity between Python and MySQL:
• Username is root
• Password is sales_emp
• The table exists in a MySQL database named “Office”.
Write the following missing statements to complete the code:
•Statement 1 – To form the cursor object
•Statement 2 – To execute the query that extracts records of those employees
whose salaries are greater than 75000.
•Statement 3 – To read the complete result of the query (records whose salaries are
greater than 75000) into the variable ‘data’.

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 12


import mysql.connector as mysql
con=mysql.connect(host="localhost",user="root",password="sales_emp",
database="Office")
mycursor=……………………………………….. #Statement 1
print("Employees with salaries greater than 75000 are : ")
____________________________ #Statement 2
data= __________________ # statement 3
for i in data:
print(i)
Ans:
•Statement 1 – mycursor=con.cursor()
•Statement 2 – mycursor.execute(“Select * from Employee where salary>75000”)
•Statement 3 – data=mycursor.fetchall()

33 What is the use of csv writer object? 5


Write a Program in Python that defines and calls the following userdefined
functions:
(i) Add_Record() – To accept and add data of an employee to a CSV file
‘record.csv’. Each record consists of a list with field elements - sid, sname and
mark to store student id, student name and marks respectively.
(ii) Count_Record() – To count the number of records present in the CSV file
named ‘record.csv’.
Ans:
Use of CSV write object – to delimit the data and write it into the csv file.
import csv
def Add_Record():
fout=open("record.csv","a",newline="")
wr=csv.writer(fout)
empid=int(input("Enter Student id :: "))
name=input("Enter Student name :: ")
marks=int(input("Enter the marks :: "))
lst=[sid,sname,mark]
wr.writerow(lst)
fout.close()
def Count_Record():
fin=open("record.csv","r",newline="")
data=csv.reader(fin)
d=list(data)
print(len(d))
fin.close()
Add_Record()
Count_Record()
OR
What is the benefit of using “with open()” method over “open()” method while
opening a file?
KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 13
Write a program in Python that defines and calls the following user-defined
functions:
(i) Add_Item() – To accept and add data of stationery items to a CSV file
‘Stationery.csv’. Each record consists of a list with field elements as Item_Id,
Item_name and Item_price to store item id, item_name and item_price.
(ii) Count() – To count the total number of stationery items whose price in more than
200 in the CSV file.
Ans:
While using with open(), the file need not to be closed explicitly.
import csv
def Add_Item():
fout=open("Stationery.csv’","a",newline="")
wr=csv.writer(fout)
id=int(input("Enter item id :: "))
name=input("Enter item name :: ")
price=int(input("Enter the price :: "))
lst=[id,sname,price]
wr.writerow(lst)
fout.close()
def Count_Record():
fin=open("record.csv","r",newline="")
data=csv.reader(fin)
d=list(data)
c=0
for i in d:
if i[2]>200:
c+=1
fin.close()
print(c)
Add_Item()
Count ()

SECTION - E
34

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 14


(i) What is the domain of ACode attribute?
(ii) Which keyword is used to sort the records of a table in descending
order?
(iii) Write a SQL commands for the following statements:
a. To display the names of all activities with their ACode in descending
order.
b. To display sum of PrizeMoney for the activities played in each of the
stadium separately.
OR ( for part (iii) only)
(iii) Give the output of the following SQL queries:
a. Select count (distinct ParticipantsNum) from Activity;
b. Select max(ScheduleDate), Min(ScheduleDate) from Activity;
Ans:
(i) Values of ACode in table Activity
(ii) DESC
(iii) (a) Select ACode, ActivityName from Activity order by Acode ;
(b) Select sum(PrizeMoney) from Activity group by Stadium;
OR
(iii) (a) 3
(b) 19-Mar-2004 12-Dec-2003
35 Shreya is a Python programmer working in a school. For the Annual Sports Event, she has 4
created a binary file ‘Result.dat’ with Student_Id, St_Name, Game_Name and Result to
store the results of students in different sports events. After the event has been
completed, she now wants to display the records of those students who won the game,
which is inserted in the Result field with ‘Won’ and ‘Loss’ data. As a Python expert, help
her complete the following code based on the requirement given above:

import _________________ # statement 1


rec=[]
while True:
Student_Id=int(input(("Enter Student Id:")))
St_name=input("Enter name:")

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 15


Game_Name=input("Enter Salary:")
Result= input("Enter Result:")
data=[Student_Id, St_Name, Game_Name,Result]
rec.append(data)
Choice=input("Wish to enter more records: Y/N")
if Choice.upper()=='N':
break
f1=____________________ # Statement2
pickle.dump(rec,f1)
print("Record added:")
fout=open("Result.dat",'rb')
res= ________________ # statement 3
count=0
for i in res:
if __________________ : #Statement 4
st_id=i[0]
st_name=i[1]
game=i[2]
result=i[3]
count+=1
print(st_id,st_name,game,result)
print("Total students are", count)
fout.close()
(i) Write a statement to import the module. (Statement 1)
(ii) Write a statement to open a binary file in write mode. (Statement 2)
(iii) Write the correct statement required to load the file. (Statement 3)
(iv) Write a statement to check if result field contains ‘Won’ or ‘won’.
(Statement4)
Ans:
(i) import pickle
(ii) f1=open(‘Result.dat’,’wb’)
(iii) res=fout(‘Result.dat’,’rb’)
(iv) if i[3] == ‘Won’ or i[3]== ‘won’:

***

KVS RO KOL – PB 2 – XII – COMP. SCI. – 2022-23 Page 16

You might also like