Set 2 Preboard 2022 Answer Key
Set 2 Preboard 2022 Answer Key
CLASS-XII
SUBJECT: COMPUTER SCIENCE
TIME: 3 HOURS M.M.: 70
General Instructions:
1. This question paper contains five sections, Section A to E.
2. All questions are compulsory.
3. Section A has 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
Q01. State True or False [1]
Ans False
Q15. Which function is used to display the total number of records from a table in a database.
a. total() (b) total(*) (c)return(*) (d) count(*) [1]
Ans (d)
Q16.In order to open a connection with MySQL database from within Python using
mysql.connector package, _______function is used. [1]
a. open() (b) connect (c) database() (d) connectdb()
Ans (b)
Q17and Q18 are assertion and reasoning based questions. Mark the correct choice as
a. Both A and B 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 and R is False.
d. A is false and R is true.
Q17 str1=”class”+”work” [1]
Assertion(A) : value of str1 will be “classwork”
Reasoning(R) : operator ‘+’ adds the operands,if both are numbers & concatenates the string if
both operands are strings.
Ans (a)
Q18. Assertion(A) : CSV (comma separated values) is a file format for data storage which looks
like a text file.
Reason (R) :The information is organized with one record on each line and each field is
separated by semicolon. [1]
Ans (c)
SECTION B
Q19. Vivek has written a code to input a number and check whether it is even or odd number.
His code is having errors. Rewrite the correct code and underline the corrections made [2]
Def checkNumber(N):
status=N%2
return
#main code
num=int(input(“enter a number to check :))
k=checkNumber(num)
if k = 0 :
print(“this is Even number”)
else:
print(“this is ODD number”)
Q20. Write two points of difference Bus topology and Star topology. [2]
OR
Write two points of difference between XML and HTML.
Ans The star topology utilises the switch or central hub for broadcasting data and info to all the
devices present in a network. On the other hand, the bus topology utilises just a single cable
that connects all the peripheral devices
XML (Extensible Markup Language) is a markup language similar to HTML, but without
predefined tags to use. Instead, you define your own tags designed specifically for your
needs.
Q22.Explain the use of ‘ Foreign Key ‘ in a Relational Database Management System. Give
example to support your answer. [2]
Ans foreign key is a primary key but in another table.
Emp (empno, ename,job,deptno) dept (deptno dname loc)
In emp table deptno is foreign key
Q24. Predict the output of the Python code given below: [2]
data = [ “L”, 20 , “M”, 40 , “N” , 60 ]
times=0
alpha=” “
add=0
for c in range(1,6,2):
times= times+c
alpha =alpha + data [c-1] + ‘@’
add= add + data [c]
print(times, add , alpha)
Ans 9 120 L@M@N@
OR
Predict the output of the Python code given below:
a=[1,2,3,4,5]
dst=[ ]
for j in range( len(a)):
if j % 2==1:
t=( a[ j ] , a [ j ] **2 )
dst.append(t)
print(dst)
Ans [(2, 4), (4, 16)]
Q25 Differentiate between order by and group by clause in SQL with appropriate example.[2]
Ans The Group By clause is used to group data based on the same value in a specific
column. The ORDER BY clause, on the other hand, sorts the result and shows it in ascending
or descending order.
OR
SECTION C
Q26 Write the output of the queries (i) to (vI) based on the table given below: [3]
TABLE : CHIPS
LAYS ONION 10 5
LAYS TOMATO 20 12
HALDIRAM SALTY 10 20
HALDIRAM TOMATO 25 30
(i) Select BRAND_NAME, FLAVOUR from CHIPS where PRICE <> 10;
Ans(i) Brand_name flavor
Lays Onion
Lays tomato
Uncle chips pudina
Haldiram salty
Haldiram tomato
(ii) Select * from chips where flavour = “tomato” and price >20;
Ans(ii) brand_name flavor price quantity
Haldiram tomato 25 30
(iii) select brand_name from chips where price > 15 and quantity <15;
Ans (iii) brand_name
lays
(iv) select count( distinct brand_name) from chips;
Ans(iv) 3
(v) select price, price*1.5 from chips where flavour=”pudina”
Ans (v) price price*1.5
10 15
(vi) select distinct (brand_name) from chips order by brand_name desc;
Ans (vi) distinct (brand_name)
Lays
Uncle chips
haldiram
Q27 Write a function countINDIA() which read a text file ‘myfile.txt’ and print the frequency of the
words ‘India’ in it(ignore case of the word). [3]
Example `; if the file content is as follows:
INDIA is my country. I live in India. India has many states.
The countIndia() function should display the output as : frequency of India is 3
Ans def countINDIA():
F=open(‘myfile.txt’)
G=F.read()
for I in G.lower():
if I ==’india’:
c=c+1
print(‘frequency of India is”,c)
F.close()
OR
Write a function countVowel() in python which read each character of a text file ‘myfile.txt’ and
then count and display the count of occurrence of vowels (including small cases and upper
case)
Example `; if the file content is as follows:
INDIA is my country. I live in India. India has many states.
The countVowel() function should display the output as :Total number of vowels are: 20
Ans
def countVowel():
F=open(‘myfile.txt’)
G=F.read()
for I in G:
if I in ‘aeiouAEIOU’:
c=c+1
print(‘total number of vowels are”,c)
F.close()
Q28 (A) Consider the following tables BOOKS and ISSUED in a database named ‘LIBRARY’.
Write SQL commands for the statements (i) to (iv). [2]
TABLE : BOOKS
TABLE:ISSUED
BID QTY_ISSUED
HIST66 10
COMP11 5
LITR88 15
(i) Display book name and author name and price of computer type books.
Ans(i) select bname,auname,price from books where type=’computer’;
(ii) To increase the price of all history books by Rs 50.
Ans(ii) update books set price=price+50 where type=’history’;
(iii) Show the details of all books in ascending order of their prices.
Ans(iii) select * from books order by price;
(iv) to display book id, book name and quantity issued for all books which have been issued.
Ans(iv)select bid,bname,qty_issued from books,issued where books.bid=issued.bid;
(B)Write the command to view all tables in a database. [1]
Ans (B) show tables;
Q29. Write a function lenFOURword(L), where L is the list of elements (list of words) passed as
argument to the function. The function returns another list named ‘indexList’ that stores the
indices of all four lettered of L. [3]
For example if L contains [‘dinesh’ , ‘ramesh’ , ‘aman’ ,’suresh’, ‘karn’]
The indexList will have [2,4]
Ans
indexList=[]
def lenFOURword(L):
for I in range(len(L)):
if len(L[I])==4:
indexList.append(I)
return indexList
L=['dinesh' , 'ramesh' , 'aman' ,'suresh', 'karn']
print(lenFOURword(L))
xiia=[]
def pushElement():
for i in L:
if i[2]=='xii' and i[3]=='a':
xiia.append([i[0],i[1]])
def popElement():
if xiia==[]:
print("stack empty")
else:
print(xiia.pop())
pushElement()
popElement()
popElement()
popElement()
OR
Write a function in Python, Push(SItem) where , Sitem is a dictionary containing the details of
stationary items-{sname:price}
The function should push the names of those items in the stack who have price greater than 25.
Also display the count of elements pushed into the stack.
For example:
If the dictionary contains the following data
ditem={‘rubber ‘ : 5 , “pencil “ : 5, ‘pen’ : 30 , ‘ notebook’ : 60 ,’eraser’ : 5 ,’watch’ : 250 }
The stack should contain
pen
notebook
watch
The output should be
The count of elements in the stack is 3
Ans
ditem={'rubber' : 5 , 'pencil' : 5, 'pen' : 30 , 'notebook' : 60 ,'eraser' : 5 ,'watch' : 250 }
st=[]
def Push(Sitem):
c=0
for i in Sitem:
if Sitem[i]>25:
st.append(i)
c=c+1
print(st)
print('count of element in the stack are',c)
Push(ditem)
SECTION D
Q31 Aryan infotech solutions has set up its new center at kamla Nagar for its office and web
based activities . The company compound has 4 buildings as shown in the diagram below:[5]
Orbit
building Sunrise
Jupiter building
building
Oracle
Building
Jupiter building 30
Oracle building 15
Sunrise building 35
Q32 (A) Write the output of the code given below: [5]
def printMe(q,r=2):
p=r+q**3
print(p)
#main code
a=10
b=5
printMe(a,b)
printMe(r=4,q=2)
Ans
1005
12
(B) The code given below inserts the following record in the table student
Rollno name clas marks
Integer string integer integer
Note the following to establish connectivity between python and MySQL
Username is root
Password is toor@123
The table exists in a “stud” database
The details (Rollno, Name, Clas and Marks) are to be 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 insert the record in the table student.
Statement 3- to add the record permanently in the database
import mysql.connector as mysql
def sqldata():
con=mysql.connect(host=”localhost”, user=”root”,passwd=”toor@123”,database=”stud”)
mycursor=________________ #statement 1 Ans statement 1 con.cursor()
rno=int(input(“enter roll number”))
name=input(“enter name”))
clas=int(input(“enter class”))
marks=int(input(“enter marks”))
querry=”insert into student values ( {}, ‘{}’,{},{} )”.format(rno,name,clas,marks)
____________ # statement 2 Ans statement 2: mycursor.execute(querry)
____________ # statement 3 Ans statement 3: con.commit()
print(“data added successfully”)
OR
add()
COUNTRECORD()
OR
Give any one point of difference between a binary file and a CSV file. Write a program in
Python that defines and calls the following user defined functions :
(i) add()- to accept and add data of an employee to a CSV file ‘ employee.csv’. Each record
consists of a list with field elements as eid, name and salary to store employee id, employee
name and employee salary respectively.
(ii) search()- to display the records of the employee whose salary is more than 40000.
Ans
import csv
def add():
f=open('employee.csv','a')
d=csv.writer(f,lineterminator='\n')
tid=input('employee id')
name=input('employee name')
salary=input('employee salary')
d.writerow([tid,name,salary])
f.close()
def search():
f=open('employee.csv')
d=csv.reader(f)
c=0
for i in d:
if int(i[2])>40000:
print(i)
add()
add()
search()
SECTION E
Q34. Layna creates a table STOCK to maintain computer stock in vidyalaya. After creation of
the table, she has entered data of 8 items in the table : [1+1+2]
Q35. Vishnu is a Python programmer. He has written a code and created a binary file recrod.dat
with studentid, subjectcode and marks. The file contains 10 records. He now has to update a
record to based on the studentid entered by the user and update the marks. The updated record
is then to be written in the file temp.dat. The records which are not to be updated also have to
be written to the file temp.dat. If the student id is not found , an appropriate message should be
displayed. As a Python expert, help him to complete the following code based on the
requirement given below: [1+1+2]
import ____________ #statement 1 Ans pickle
def update _data():
rec={ }
fin=open(‘record.dat’, ‘rb’)
fout=open(‘ ___________’) #statement 2 Ans ‘temp.dat’,’ab’
found=False
sid=int(input(‘enter student id to update the marks ‘))
While True:
try:
rec=_________#statement 3 Ans pickle.load(fin)
if rec[‘studentid’]==sid:
found=True
rec[‘marks’]=int(input(‘enter new marks’))
pickle. _________ #statement 4 Ans dump(rec,fout)
else:
pickle.dump(rec,fout)
except:
break
if found==True:
print(‘the marks of studentid’ ,sid, ‘has been updated’)
else:
print(‘ no student with such id is not found’)
fin.close()
fout.close()
(i) which module should be imported in the program?(statement 1)
(ii) write the correct statement required to open a temporary file named
temp.dat(statement 2)
(iii) Which statement should Aryan fill in statement 3 to read the data from the
binary file, record.dat and in statement 4 to write the updated data in the file,
temp.dat?