Professional Documents
Culture Documents
Angalore Sahodaya Schools Complex Association (Bssca)
Angalore Sahodaya Schools Complex Association (Bssca)
Class: XII
PRE-BOARD EXAMINATION (2022-23)
SET 1 ANSWER KEY
DATE : 11.01.23 Max marks : 70
SUBJECT: Computer Science (083) Time : 3 hours
General Instructions:
1. This question paper contains five sections, Section A to E.
2. All questions are compulsory.
3. Section A have 18 questions carrying 01 mark each.
4. Section B has 07 Very Short Answer type questions carrying 02 marks each.
5. Section C has 05 Short Answer type questions carrying 03 marks each.
6. Section D has 03 Long Answer type questions carrying 05 marks each.
7. Section E has 02 questions carrying 04 marks each. One internal choice is
given in Q34 against part c only.
8. All programming questions are to be answered using Python Language only.
SECTION A
1. Write the type of the tokens for the following 1
i. == ii. :
Ans: Operator and punctuator
6. To read the entire remaining contents of the file as a string from a file object infile, we use
____________ 1
a. infile.read(2)
b. infile.read()
c. infile.readline()
d. infile.readlines()
Ans : b infile.read()
7. An attribute in a relation is a foreign key if it is the ___________ key in any other relation.
a. Candidate 1
b. Primary
c. Alternate
d. Foreign
Ans : b Primary
a) no difference
b) in r+ the pointer is initially placed at the beginning of the file and the pointer is at the
end for w+
c) in w+ the pointer is initially placed at the beginning of the file and the pointer is at
the end for r+
d) depends on the operating system
Ans: b in r+ the pointer is initially placed at the beginning of the file and the pointer
is at the end for w+
12. Which clause is used to “sort the rows of the final result set by one or more columns”?
a) HAVING 1
b) ORDER BY
c) WHERE
d) FROM
Ans: b ORDER BY
13. Users are able to see a pad-lock icon in the address bar of the browser when there is
___________ connection. 1
a. HTTP
b. SMTP
c. HTTPS
d. FTP
Ans : c. HTTPS
15. The referential integrity constraint of a relational database can be specified with the help
of? 1
a. Primary Key
b. Super Key
c. Foreign Key
d. None of the above
Ans : c Foreign Key
a. fetch()
b. fetchone()
c. fetchmany()
d. fetchall()
Ans :c. fetchmany( )
17. Assertion - In a function header, any parameter cannot have a default value unless all
parameters appearing on its right have their default values.
Reason - Non- default arguments cannot follow default arguments. 1
A - Both A and R are true and R is the correct explanation of A.
B - Both A and R are true but R is not the correct explanation of A.
C - A is true but R is false.
D - A is false but R is true.
Ans : A Both A and R are true and R is the correct explanation of A.
18. Assertion - The with statement simplifies the working with files but does not support
exception handling. 1
Reason – The with statement will automatically close the file after the nested block of code.
A - Both A and R are true and R is the correct explanation of A.
B - Both A and R are true but R is not the correct explanation of A.
C - A is true but R is false.
D - A is false but R is true.
Ans : D - A is false but R is true.
SECTION B
19. Rewrite the following code in python after removing all syntax error(s). Underline each
correction done in the code: 2
a=5
work=true
b=hello
c=a+b
FOR i in range(10)
if i%7=0:
continue
Ans:
a=5
work=True
b= ’hello’
c=a+b
for i in range(10):
if i%7= =0:
continue
( ½ mark for each error)
22. What is data redundancy? List two problems associated with it. 2
Ans:
Duplication of data is data redundancy.
It leads to problems like wastage of space and inconsistent data in a relation
( 1 mark for each correct answer)
What is Nic?
Ans :
Nic stands for network interface card. It is also known as network adapter. It is in the
form of adding card and is installed in a computer so that the computer can be
connected to our network. Each nic has a Mac address which helps in identify the
computer on a network.
OR
A=[1,2,3]
B=[5,6,7]
for i in range(1,3):
A[i-1]=A[i]+1
for i in range(0,3):
print(A[i],end='-')
print()
for i in range(1,3):
B[i-1] =B[i]+1
for i in range(0,3):
print(B[i],end='#')
print()
Ans:
3-4-3-
7#8#7#
(1 mark for each line of correct output)
25. What do you understand by the terms primary key and degree of a relation in relational
data base? Illustrate with an example. 2
Ans:
Primary Key: A primary key is a set of one or more attributes that can uniquely identify
tuples within the relations.
The number of attributes in a relation is called Degree of a relation in relational data base.
SECTION C
26. a. Consider the following two tables :- 1+2
Table : ITEM
i. SELECT TITLE, AUTHOR, PUB FROM BOOKS WHERE TYPE LIKE “OS”;
Ans:
+-------------------+--------+------+
| TITLE | AUTHOR | PUB |
+-------------------+--------+------+
| DOS Guide | Norton | PHI |
| Mastering Windows | Cowart | BPB |
+-------------------+--------+------+
iii. SELECT SUM(PRICE), TYPE FROM BOOKS GROUP BY PUB HAVING PUB LIKE
'BPB';
Ans :
+------------+------+
| SUM(PRICE) | TYPE |
+------------+------+
| 695 | PROG |
+------------+------+
iv. SELECT AVG(PRICE) FROM BOOKS WHERE QTY BETWEEN 1 AND 2;
Ans :
+------------+
| AVG(PRICE) |
+------------+
| 145.0000 |
+------------+
( ½ mark for each correct output)
27. Write a method COUNT_DO() to count the presence of a word ‘do’ in a text file
“MEMO.txt” 3
Example:
If the content of the file is:
I will do it, if you request me to do it.
It would have been done much earlier.
Output should be : 2
Note: In the above example, ‘do’ occurring as a part of the word done is not
considered.
Ans :
def COUNT_DO():
file = open('MEMO.txt', 'r')
count = 0
for line in file:
words = line.split()
for i in words:
if i=='do':
count+=1
file.close()
print("No. of occurences of 'do': ", count)
COUNT_DO()
( ½ mark for correctly opening and closing the file
½ for readlines()
½ mar for correct loop
½ for correct if statement
½ mark for correctly incrementing count
½ mark for displaying the correct output)
OR
Write a method wordcount() which accepts the name of a text file and displays the number
of words present in the file which have the same first and last letter (Ex: Pump, trot).
Ans :
def wordcount(file_name):
file = open(file_name, 'r')
print('Content of given file:')
for line in file:
print(line)
words = line.split()
print('Words having first and last letter same:')
for i in words:
if i[0].lower()==i[-1].lower():
print(i, end = ' ')
file.close()
x = input("Enter file name")
y = x + '.txt'
wordcount(y)
( ½ mark for correctly opening and closing the file
½ for readlines()
½ mar for correct loop
½ for correct if statement
½ mark for correctly incrementing count
½ mark for displaying the correct output)
28. a. Write the outputs of the SQL queries (i) to (iv) based on the relations SCHOOL and
Admin given below: 2+1
SCHOOL
CODE TEACHERNAME SUBJECT DOJ PERIO EXPERI
DS ENCE
1001 UMA SHANKAR ENGLISH 12/03/2000 24 10
1009 NANDITA RAI PHYSICS 03/09/1998 26 12
1203 LISA ANAND ENGLISH 09/04/2000 27 5
1045 YASHRAJ MATHS 24/08/2000 24 15
1123 JEEVAN PHYSICS 16/07/1999 28 4
1167 HARISH B CHEMISTRY 19/10/1999 27 5
1215 RAMESH PHYSICS 11/05/1998 22 16
ADMIN
CODE GENDER DESIGNATION
1001 MALE VICE PRINCIPAL
1009 FEMALE COORDINATOR
1203 FEMALE COORDINATOR
1045 MALE HOD
1123 MALE SENIOR TEACHER
1167 MALE SENIOR TEACHER
1215 MALE HOD
29. Write a definition of a method(function) odd-sum() which receives the list of numbers as
parameter and finds the sum of odd numbers in the list. 3
Example :
Enter a list of no.s[12,53,45,11,66,98,77]
Sum of odd no.s in list 186
Ans:
def odd_sum(x):
sum1 = 0
for i in x:
if i%2!=0:
sum1+=i
print("Sum of odd no.s in list", sum1)
l = eval(input("Enter a list of no.s"))
odd_sum(l)
(½ mark for correct function header
1 mark for correct loop
1 mark for correct if statement
½ mark for printing output)
30. Arr is a list of numbers. Write a function PUSH(Arr), to push all numbers divisible by 5
from the list Arr to the stack. Display the stack if it has at least one element otherwise
display an appropriate message. 3
Ans :
def PUSH(Arr,value):
s=[]
for x in range(0,len(Arr)): if Arr[x]%5==0:
s.append(Arr[x])
if len(s)==0:
print("Empty Stack")
else:
print(s)
OR
Write a function in Python, Push(Player) where , Player is a dictionarycontaining the details of
stationary items– {Game:name}.
The function should push the names of those payers into the stack where the name starts with
letter ‘R’. Also display the count of elements pushedinto the stack.
For example:
If the dictionary contains the following data:
Players={"Cricket": “RahulDravid”,"Chess": “R Pragnananda “, "Kho-Kho":
“Sarika Kale”, "Kabaddi": “Pardeep Narwal”}
SECTION D
31. Riana Medicos Centre has set up its new centre in Dubai. It has four
buildings as shown in the diagram given below:
provide the best possible answer for the following queries:
i. Suggest the type of network established between the buildings.
Ans :
ii. Suggest the most suitable place (i.e., building) to house the server of this
Organization. Justify Your answer
Ans :The most suitable place/ building to house the server of this organization would
be building Research Lab, as this building contains the maximum number of computers.
b. The code given below reads the following record from the table named Doctors and
displays only those records who are Dermotologists:
DNo – integer
DName – string
Dept – string
• Username is root
• Password is tiger
• The table exists in a MYSQL database named Hospital.
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 all the
dermotologists
Statement 3- to read the complete result of the query (records of
dermotologists) into the object named content from the
table doctors.
import mysql.connector as ms
def doc_data():
con1=ms.connect(host="localhost", user="root",password="tiger",
database="Hospital")
mycursor= __________________ #Statement 1
print("Details of dermotologists are :")
_______________________ #Statement 2
content = #Statement 3
for i in content:
print(i)
print()
Ans:
Statement 1: con1.cursor()
Statement 2: mycursor.execute("select * from doctors where dept like
“Dermotologists” ")
Statement 3: mycursor.fetchall()
(1 mark for each correct answer)
OR
a. Predict the output of the code given below
poet= "ShakESpHerE"
l=len(poet)
r=""
for i in range(l):
if poet[i].islower():
r+=poet[i-1]
elif poet[i].isupper():
if poet[i]=='S':
r+='X';
elif(poet[i]=='E'):
r+=poet[i-1].upper()
else:
r+=chr(ord(poet[i])-1)
print(" Output : ",r)
Ans:
Output : XShaXSHe
(1 mark for first 4 characters, 1 mark for next 4 characters)
b. The code given below inserts the following record in the table teacher:
Tid – integer
TName – string
cls – integer
Dept – string
Note the following to establish connectivity between Python andMYSQL:
✓ Username is root
✓ Password is tiger
✓ The table exists in a MYSQL database named school.
✓ The details (Tid, TName, cls and Dept) are accepted from the user.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table
teacher.
Statement 3 – to add the record permanently in the database
import mysql.connector as m
def connecting():
con1=m.connect(host="localhost",user="root", password="tiger",
database="school")
mycursor= ________________#Statement 1
Tid=int(input("Enter Teacher id :: "))
TName=input("Enter Teacher name :: ")
cls=int(input("Enter class thought :: "))
Dept=input("Enter department :: ")
querry="insert into student
values({},'{}',{},{})".format(Tid,TName,cls,Dept)
____________________#Statement 2
____________________# Statement 3
print("Data Added successfully")
Ans :
Statement 1: con1.cursor()
Statement 2: mycursor.execute(querry)
Statement 3: con1.commit()
(1 mark for each correct answer)
Ans : flush() allows the user to send content in file before closing the file. It means when
flush() is used it will clear the buffer and transfer content to file.
import CSV
def InsRec(eid,ename,sal): #to write/add data into the CSV file
fo=open('emp.csv','a')
writer=csv.writer(fo)
writer.writerow([eid,ename,sal])
fo.close()
def search():
fin=open("emp.csv","r",newline='\n')
data=csv.reader(fin)
found=False
print("The Details are")
for i in data:
if ((i[2])>10000):
found=True
print(i[0],i[1],i[2])
if found==False:
print("Record not found")
fin.close()
SECTION E
34. Sahana is creating a table named Football as shown below in the database sports. 4
Table : Football
He has succeeded in writing partial code and has missed out certain statements, so
he has left certain queries in comment lines. You as an expert of Python have to
provide the missing statements and other related queries based on the following
code of ParasNath.
As a Python expert, help him to complete the following code based on requirement
given above:
import pickle
def AddStudents():
____________# statement1 : to open the binary file towrite data
while True:
Rno = int(input("Rno :"))
Name = input("Name : ")
Percent = float(input("Percent :"))
L = [Rno, Name, Percent]
#statement2 : to write the list L into the file
Choice = input("enter more (y/n): ")
if Choice in "nN":
break
F.close()
def GetStudents():
Total=0
Countrec=0
Countabove75=0
with open("STUDENT.DAT","rb") as F:
while True:
try:
__________#statement3: to read from the file
Countrec+=1
Total+=R[2]
if R[2] > 75:
print(R[1], " has percent = ",R[2])
Countabove75+=1
except:
break
if Countabove75==0:
print("There is no student who haspercentage more than 75")
average=Total/Countrec
print("average percent of class = ",average)
AddStudents()
GetStudents()
2. What command should be used to write the list L into the binary file,
STUDENT.DAT in statement2
Ans : pickle.dump(L,F) //cannot write small f
3. What command should be used to read each record from the binaryfile
STUDENT.DATin statement3
Ans R = pickle.load(F)
4. Which of the following statement(s) are correct regarding the file access
modes?
a. ‘r+’ opens a file for both reading and writing. File object points to itsbeginning.
b. ‘w+’ opens a file for both writing and reading. Adds at the end of theexisting
file if it exists and creates a new one if it does not exist.
c. ‘wb’ opens a file for reading and writing in binary format. Overwritesthe file if it
exists and creates a new one if it does not exist.
d. ‘a’ opens a file for appending. The file pointer is at the start of the fileif the file
exists.
Ans : a
(1 mark for each correct answer)