Computer Science (083) Class 12
Computer Science (083) Class 12
BENGALURU REGION
FIRST PRE-BOARD EXAM (SESSION 2022-23)
1|Page
6. Which of the file opening mode will open the file for reading and writing in 1
binary mode.
a) rb b) rb+ c) wb d) a+
A rb+
7. Which of the following statements is True? 1
a) There can be only one Foreign Key in a table.
b) There can be only one Unique key is a table
c) There can be only one Primary Key in a Table
d) A table must have a Primary Key.
A There can be only one Primary Key in a Table
8. Which of the following is not part of a DDL query? 1
a) DROP
b) MODIFY
c) DISTINCT
d) ADD
A DISTINCT
9. Which of the following operations on a string will generate an error? 1
a) "PYTHON"*2
b) "PYTHON" + "10"
c) "PYTHON" + 10
d) "PYTHON" + "PYTHON"
A "PYTHON" + 10
10. _______________ Keyword is used to obtain unique values in a SELECT 1
query
a) UNIQUE
b) DISTINCT
c) SET
d) HAVING
A DISTINCT
11. Which of the following python statement will bring the read pointer to 10th 1
character from the end of a file containing 100 characters, opened for
reading in binary mode.
a) File.seek(10,0)
b) File.seek(-10,2)
c) File.seek(-10,1)
d) File.seek(10,2)
A File.seek(-10,2)
2|Page
12. Which statement in MySql will display all the tables in a database? 1
a) SELECT * FROM TABLES;
b) USE TABLES;
c) DESCRIBE TABLES;
d) SHOW TABLES;
A SHOW TABLES;
13. Which of the following is used to receive emails over Internet? 1
a) SMTP b) POP3 c) PPP d) VoIP
A POP3
14 What will be the output of the following python expression? 1
print(2**3**2)
a) 64 b) 256 c) 512 d) 32
A 512
15. Which of the following is a valid sql statement? 1
a) ALTER TABLE student SET rollno INT(5);
b) UPDATE TABLE student MODIFY age = age + 10;
c) DROP FROM TABLE student;
d) DELETE FROM student;
A DELETE FROM student;
16. Which of the following is not valid cursor function while performing database 1
operations using python. Here Mycur is the cursor object?
a) Mycur.fetch()
b) Mycur.fetchone()
c) Mycur.fetchmany(n)
d) Mycur.fetchall()
A Mycur.fetch()
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): A variable declared as global inside a function is visible with 1
changes made to it outside the function.
Reasoning (A): All variables declared outside are not visible inside a function
till they are redeclared with global keyword.
A Both A and R are true and R is the correct explanation for A
3|Page
18. Assertion (A): A binary file in python is used to store collection objects like 1
lists and dictionaries that can be later retrieved in their original form using
pickle module.
Reasoning (A): A binary files are just like normal text files and can be read
using a text editor like notepad.
A A is True and R is False
SECTION B
19. Sameer has written a python function to compute the reverse of a number. 2
He has however committed a few errors in his code. Rewrite the code after
removing errors also underline the corrections made.
define reverse(num):
rev = 0
While num > 0:
rem == num %10
rev = rev*10 + rem
num = num//10
return rev
print(reverse(1234))
A def reverse(num):
rev = 0
while num > 0:
rem = num %10
rev = rev*10 + rem
num = num//10
return rev
print(reverse(1234))
20. Mention two differences between a Hub and a switch in networking. 2
OR
Mention one advantage and one disadvantage of Star Topology.
A Hub Switch
Hub is a passive Device Switch is an active device
Hub broadcasts messages to all Switch sends the messages to
nodes intended node.
Or any other valid difference between the two. Each difference carries 1
mark.
OR
Advantage: The network remains operational even if one of the nodes stops
working.
Disadvantage: The network stops working if the central hub stops working.
Or any other valid advantage or disadvantage. Each carries 1 mark
4|Page
21. a) What will be the output of the following string operation. 1
str="PYTHON@LANGUAGE"
print(str[2:12:2])
OR
Predict the output of the following python code:
data = [2,4,2,1,2,1,3,3,4,4]
d = {}
for x in data:
5|Page
if x in d:
d[x]=d[x]+1
else:
d[x]=1
print(d)
A ['F', 'U', 'N'] ['D', 'A', 'Y'] Each list correctly written will fetch 1 mark. ½ mark
can be given if the list is figured out in the answer.
OR
{2: 3, 4: 3, 1: 2, 3: 2}
The dictionary elements can be written in any order.
25. A MySQL table, sales have 10 rows. The following queries were executed on 2
the sales table.
SELECT COUNT(*) FROM sales;
COUNT(*)
10
OR
6|Page
Relation: Emp
Relation: Dept
empcode ename deptid Salary
deptid dname
1001 TOM 10 10000
10 Physics
1002 BOB 11 8000
11 Chemistry
1003 SID 10 9000
b) Write output of the queries (i) to (iv) based on the table Sportsclub
Table Name: Sportsclub
playerid pname sports country rating salary
7|Page
i) DISTINCT sports
SOCCER
TENNIS
CRICKET
ATHLETICS
SNOOKER
ii)
Sports MAX(salary)
SOCCER 50000
TENNIS 20000
CRICKET 15000
ATHLETICS 12000
iii)
pname sports salary
VIRAT CRICKET 15000
NEERAJ ATHLETICS 12000
SANIA TENNIS 5000
iv)
SUM(salary)
15000
27. A pre-existing text file data.txt has some words written in it. Write a python 3
function displaywords() that will print all the words that are having length
greater than 3.
Example:
For the fie content:
A man always wants to strive higher in his life
He wants to be perfect.
OR
A pre-existing text file info.txt has some text written in it. Write a python
function countvowel() that reads the contents of the file and counts the
occurrence of vowels(A,E,I,O,U) in the file.
8|Page
A def displaywords():
f = open('data.txt','r')
s = f.read()
lst = s.split()
for x in lst:
if len(x)>3:
print(x, end=" ")
f.close()
OR
def countvowels():
f - open('info.txt', 'r')
s = f.read()
count = 0
for x in s:
if x in 'AEIOU':
count+=1
print(count)
f.close()
Correct definition of function will fetch 3 marks. For each syntax error ½
mark may be deducted. No marks to be deducted for using a different logic.
28. Based on the given set of tables write answers to the following questions. 3
Table: flights
flightid model company
10 747 Boeing
12 320 Airbus
15 767 Boeing
Table: Booking
ticketno passenger source destination quantity price Flightid
10001 ARUN BAN DEL 2 7000 10
10002 ORAM BAN KOL 3 7500 12
10003 SUMITA DEL MUM 1 6000 15
10004 ALI MUM KOL 2 5600 12
10005 GAGAN MUM DEL 4 5000 10
a) Write a query to display the passenger, source, model and price for all
bookings whose destination is KOL.
b) Identify the column acting as foreign key and the table name where it
is present in the given example.
9|Page
A a) SELECT passenger, source, model, price FROM booking, flights WHERE
bookings.flightid = flights.flightid AND destination='KOL';
L = [12,10,15,20,25]
modilst(L)
print(L)
OR
10 | P a g e
A data={'India':140, 'USA':50, 'Russia':25, 'Japan':10}
stack=[]
def push(stack, data):
for x in data:
if data[x]>25:
stack.append(x)
push(stack, data)
print(stack)
OR
data = [1,2,3,4,5,6,7,8]
stack = []
def push(stack, data):
for x in data:
if x % 2 == 0:
stack.append(x)
def pop(stack):
if len(stack)==0:
return "stack empty"
else:
return stack.pop()
push(stack, data)
print(pop(stack))
SECTION D
31 Magnolia Infotech wants to set up their computer network in the Bangalore 5
. based campus having four buildings. Each block has a number of computers
that are required to be connected for ease of communication, resource
sharing and data security. You are required to suggest the best answers to
the questions i) to v) keeping in mind the building layout on the campus.
11 | P a g e
HR
Development
Admin
Logistics
Number of Computers.
Block Number of computers
Development 100
HR 120
Admin 200
Logistics 110
i) Suggest the most appropriate block to host the Server. Also justify
your choice.
ii) Suggest the device that should should be placed in the Server
building so that they can connect to Internet Service Provider to
avail Internet Services.
iii) Suggest the wired medium and draw the cable block to block layout
to economically connect the various blocks.
iv) Suggest the placement of Switches and Repeaters in the network
with justification.
v) Suggest the high-speed wired communication medium between
Bangalore Campus and Mysore campus to establish a data network.
A i) Admin Block since it has maximum number of computers.
ii) Modem should be placed in the Server building
iii) The wired medium is UTP/STP cables.
Development HR
Admin
Logistics
12 | P a g e
iv) Switches in all the blocks since the computers need to be
connected to the network. Repeaters between Admin and HR block
& Admin and Logistics block. The reason being the distance is more
than 100m.
v) Optical Fiber cable connection.
OR (only in a part)
13 | P a g e
import ________________ as myc # Statement 1
con = myc.connect(host="locahost", user="root", passwd="",
database="mydb")
mycursor = __________________ #Statement 2
sql = "UPDATE student SET age=age+2 WHERE class='XI'"
mycursor.execute(sql)
sql = "SELECT * FROM student"
mycursor=con.execute(sql)
result = _____________________ #Statement 3
for row in result:
print(row)
A a) 70 40 30
110 60 50
1 mark for each correct row of answer. Partial marks to be given if
partial correct answers are there.
OR
**dAys
2 marks for correct answer. Partial marks may be given for partially
correct answer.
b) mysql.connector
c) con.cursor()
d) mycursor.fetchall()
14 | P a g e
b) A function read() that reads the data from the binary file and displays
the dictionaries whose age is 16.
A import pickle
def insert():
d1 = {'Rollno':1001, 'Name':'TOM', 'Age':17}
d2 = {'Rollno':1002, 'Name':'BOB', 'Age':16}
d3 = {'Rollno':1003, 'Name':'KAY', 'Age':16}
f = open("data.dat","wb")
pickle.dump(d1,f)
pickle.dump(d2,f)
pickle.dump(d3,f)
f.close()
def read():
f = open("data.dat", "rb")
while True:
try:
d = pickle.load(f)
if d['Age']==16:
print(d)
except EOFError:
break
f.close()
The insert() function has 2 marks. Deduct ½ mark for each syntax error
The read() function carries 3 marks. Deduct ½ marks for each syntax error
34 Tarun created the following table in MySQL to maintain stock for the items 1+1+
. he has. 2
Table : Inventory
Productid pname company stock price rating
15 | P a g e
a) Identify the primary key in the table with valid justification.
b) What is the degree and cardinality of the given table.
c) Write a query to increase the stock for all products by 20 whose
company is Parley.
OR (only for part c)
Write a query to delete all the rows from the table which are not
having any rating.
A a) The Primary Key should be Productid since it uniquely identifies each
row. (1)
b) Degree – 6 Cardinality – 6 (½ + ½)
c) UPDATE inventory SET stock=stock+10 WHERE company = 'Parley';
OR
DELETE FROM inventory WHERE RATING IS NULL; (2)
35 Sudheer has written a program to read and write using a csv file. He has
. written the following code but failed to write completely, leaving some
blanks. Help him to complete the program by writing the missing lines by
following the questions a) to d)
_________________ #Statement 1
headings = ['Country','Capital','Population']
data = [['India', 'Delhi',130],['USA','Washington DC',50],[Japan,Tokyo,2]]
f = open('country.csv','w', newline="")
csvwriter = csv.writer(f)
csvwriter.writerow(headings)
________________ #Statement 2
f.close()
f = open('country.csv','r')
csvreader = csv.reader(f)
head = _________________ #Statement 3
print(head)
for x in __________: #Statement 4
if int(x[2])>50:
print(x)
16 | P a g e
A a) import csv
b) csvwriter.writerows(data)
c) next(csvreader)
d) csvreader
1 mark for each correct answer.
****End****
17 | P a g e