Professional Documents
Culture Documents
SET 2 Ans Key
SET 2 Ans Key
Class: XII
PRE-BOARD EXAMINATION (2022-23)
SET 2 ANSWER KEY
DATE : 11.01.23 Max marks : 70
SUBJECT: Computer Science (083) Time : 3 hours
General Instructions:
Section A
Ans : [1, 2, 3, 4]
count={}
count[(1,2,4)] = 5
count[(4,2,1)] = 7
count[(1,2)] = 6
count[(4,2,1)] = 2
tot = 0
for i in count:
tot=tot+count[i]
print(len(count)+tot)
A. 16
B. 17
C. 25
D. Tuples can’t be made keys of a dictionary
Ans :- A 16
10. Suppose you have two columns named student_name and student_department inside
table student_details and you are asked to update the value of these two columns
where ID=4 then what statement you will write? 1
12. Which clause is used to “Modify the existing field of the table”? 1
a) ALTER
b) UPDATE
c) SELECT
d) MODIFY
Ans: a. ALTER
13. Which of the following devices modulates digital signals into analog signals that
can be sent over telephone lines 1
a. Router
b. Gateway
c. Bridge
d. Modem
Ans : d. modem
16. Which attribute is used to return number of rows that are affected by an execute()
method. 1
a. rows()
b. count()
c. rowcount()
d. returncount()
Ans: rowcount()
Q17 and 18 are ASSERTION AND REASONING based questions. Mark the correct
appropriate choice.
17. Assertion - A function ends the moment it reaches a return statement or all the
statements in function body have been executed.
Reason – Return statement ends a function execution even if it is in the middle of
the function.
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 open a file one should use the open() function, open() is a built
in function
Reason - The open () functions returns a file object, it is used to read or modify the
file accordingly.
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: B - Both A and R are true but R is not the correct explanation of A.
SECTION B
19. Rewrite the following code in python after removing all syntax error(s). Underline
each correction done in the code 2
def sum(c)
s=0
for i in Range(1, c+1)
s=s+i
return s
print(sum(5)
Ans:
def sum(c):
s=0
for i in range(1, c+1):
s=s+i
return s
print(sum(5))
( ½ mark for each error)
20. Differentiate two pints between PAN and LAN types of networks. 2
Ans :
PAN LAN
PAN is a computer network LAN interconnects some
organized around an individual standalone computers within a
person, where a small network is confirmed physical area up to
formed by connecting various a kilometre.
devices of the individual.
Devices in one PAN network can The network does not contain
establish connection with other more than one subnet because
devices in other PAN network they are controlled by one
when in the same range. administrator.
Example: a laptop, a printer, a Example a LAN inside a
smartphone, digital recorder. Etc University or a LAN inside a
hospital. Etc.
( One mark for each difference )
OR
Write two differences between Packet Switching and Message Switching
Ans :
22. What are aggregate and scalar functions in MYSQL? Give one example for each 2
Ans:
Aggregate functions work on multiple tuples’ values for an attribute and return
single summarised value for a group of tuples.
Ex: sum()
The scalar functions work individually with each tuple’s value for an attribute and
return the result for each tuple.
Ex: now(), year(), lcase()
( 1 mark for each correct anwer)
Ans:
i. CDMA. Code division multiple access.
ii. XML. Extensible markup language.
(½ mark for every correct full form)
str1=list("Sn04")
for i in range(len(str1)):
if i==3:
x=int(i)
x+=x-3
str1[i]=x
elif (str1[i].islower()):
str1[i]=str1[i].upper()
else:
str1[i]=str1[i]*2
print(str1)
25. Differentiate between Candidate key and Primary key in context of RDBMS.
Illustrate with an example. 2
Ans:
Candidate Key: All attribute combinations inside a relation that can serve primary
key are Candidate Keys as they are candidates for the primary key position.
Primary Key: A primary key is a set of one or more attributes that can uniquely
identify tuples within the relations.
Table : CLIENT
Table HOSPITAL
No Name Age Department Dateofadm Charges Sex
1 Arpit 34 Surgery 21/01/04 300 M
2 Anush 60 ENT 11/04/05 250 M
3 Nilofer 45 Orthopedic 19/11/04 500 F
4 Jackie 47 Surgery 20/05/06 600 F
5 Bret 20 ENT 19/04/05 200 M
6 Anthea 46 ENT 23/09/05 200 F
7 Bindu 38 Cardiology 15/08/04 450 F
8 Deepak 25 Cardiology 14/11/05 450 M
9 Zain 9 Nuclear Medicine 14/12/06 700 M
10 Zeba 47 Gynecology 1/1/2006 350 F
i. select name, age, sex from hospital where department like "cardiology";
Ans:
-------- ------ ------
name age sex
+--------+------+------+
| Bindu | 38 | F |
| Deepak | 25 | M |
+--------+------+------+
ii. select name, dateofadm from hospital where department = "ENT" and sex like 'F';
Ans :
+--------+------------+
| name | dateofadm |
+--------+------------+
| Anthea | 2023-09-05 |
+--------+------------+
Ans:
+------------ +----------+-------------- +
| department | count(*) | min(charges) |
+------------ +---------- +-------------- +
| ENT | 3| 200 |
+------------ +---------- +-------------- +
iv. select distinct(department) from hospital order by department;
Ans:
+------------------+
| department |
+------------------+
| Cardiology |
| ENT |
| Gynecology |
| Nuclear Medicine |
| Orthopedic |
| Surgery |
+------------------+
( ½ Mark for each correct output)
27. Write a method countcap( ) in python to count the number of upper case alphabets
present in a text file “ARTICLE.txt” 3
Example :
If the file contains the given below content:
Ans:
def countcap():
file = open('poem1.txt', 'r')
count = 0
chr = file.read()
print(chr)
for i in chr:
if i.isupper():
count+=1
print("Total no.of uppercase alphabets:", count)
file.close()
countcap()
( ½ 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 RevText() to read a text file “input.txt” and print the text in reverse order.
Example:
If the file content is as follows: I LOVE MY NATION
Output will be: NOITAN YM EVOL I
Ans :
def RevText():
file = open('input.txt', 'r')
for i in file:
print(i[-1::-1])
file.close()
RevText()
( ½ 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 Club and
Coach given below: 3
Table : Club
Coach-id CoachName Age Sports DateOfApp Pay Sex
1 KUKREJA 35 KARATE 27/03/1996 1000 M
2 RAVINA 34 KARATE 20/01/1998 1200 F
3 KARAN 34 SQUASH 19/02/1999 2000 M
4 TARUN 33 BASKETBALL 01/01/1999 1500 M
5 ZUBIN 36 SWIMMING 12/01/1998 750 M
6 KETAKI 36 SWIMMING 24/02/1997 800 F
7 ANKITA 39 SQUASH 20/02/1998 2200 F
8 ZAREEN 37 KARATE 22/02/1997 1100 F
9 KUSH 41 SWIMMING 13/01/1997 900 M
10 SHAILYA 37 BASKETBALL 19/02/1998 1700 M
Table :Coach
Sports person Sex Coach-id
AJAY M 1
SEEMA F 2
VINOD M 1
TANEJA F 3
VIKRAM M 9
ii. SELECT COACHNAME, AGE, PAY, 15/100*PAY+PAY BONUS FROM CLUB WHERE
DATEOFAPP < '01-JAN-1998';
Ans :
COACHNAME AGE PAY BONUS
-------------------- ---------- ---------- ----------
KUKREJA 35 1000 1150
KETAKI 36 800 920
ZAREEN 37 1100 1265
KUSH 41 900 1035
iii. SELECT COACHNAME, SPORTSPERSON FROM CLUB, CLUBPERSON WHERE
CLUB.SEX LIKE 'M' AND CLUBPERSON.SEX LIKE 'F'AND CLUB.COACHID =
CLUBPERSON.COACHID;
Ans:
COACHNAME SPORTSPERSON
-------------------- --------------
KARAN TANEJA
29. Write a void function that receives a 4-digit no. and calculates the sum of the
squares of each digit in the number. 3
Example :
Enter a 4-digit no.1234
Sum of squares of digits 30
Ans :
def f(x):
sum1 = 0
while x>0:
dig=x%10
x//=10
sum1+=(dig**2)
print("Sum of squares of digits", sum1)
n = int(input("Enter a 4-digit no."))
f(n)
(½ mark for correct function header
1 mark for correct loop
1 mark for correct sum of squares
½ mark for printing output)
30. Write functions of a program to implement a stack for these book details (bookno,
bookname). That is, now each item of node of stack contains 2 types of information
as a list element. Implement Push and Display operations for the stack of books.
3
Ans :
stk=[bookno,bookname]
def isEmpty(stk):
if stk == []:
return True:
else:
return False:
def Push(stk,item ):
stk.append(item)
top=len(stk)-1
def Display():
if isEmpty(stk):
print(“Stack empty”)
else:
top = len(stk)-1
print(stk[top], “<-” )
for a in range(top-1, -1,-1):
print(stk[a])
(1.5 marks for correct push_element() and 1.5 marks for correct
pop_element())
OR
Write a function in python named PUSH(STACK, SET) where STACK is list of
some numbers forming a stack and SET is a list of some numbers. The function will
push all the EVEN elements from the SET into a STACK implemented by using a
list. Display the stack after push operation.
SECTION D
31. Intelligent Hub India is a knowledge community aimed to uplift the standard of
skills and knowledge in the society. It is planning to setup its training centres in
multiple towns and villages pan India with its head offices in the nearest cities.
They have created a model of their network with a city, a town and 3 villages as
follows:
As a network consultant, you have to suggest the best network related solutions for
their issues/problems raised in (i) to (v), keeping in mind the distances between
various locations and other given parameters. 5
i. Suggest the most appropriate location of the SERVER in the YHUB (out of the
4 locations), to get the best and effective connectivity. Justify your answer. 1
ii. Suggest the best wired medium and draw the cable layout (location to location)
to efficiently connect various locations within the YHUB. 1
iv. Which hardware device will you suggest to connect all the computers within
each location of YHUB? 1
Ans :
i.
YTOWN
Justification
Since it has the maximum number of computers.
It is closest to all other locations.
(½ mark for naming the server block and ½ mark for correct reason.)
32.
a. Predict the output of the code given below 2+3
def Display(str):
m=" "
for i in range(0,len(str)):
if(str[i].isupper()):
m=m+str[i].lower()
elif str[i].islower():
m=m+str[i].upper()
else:
if i%2==0:
m=m+str[i-1]
else:
m=m+"#"
print(m)
Display('CBSE@dec22')
Ans :
cbseDEC#
(1mark for first 4 characters and 1 mark for last 4 characters)
b. The code given below inserts the following record in the table Student:
rno – integer
Name – string
cls – integer
Mks – integer
Note the following to establish connectivity between Python andMYSQL:
Username is root
Password is tiger
The table exists in a MYSQL database named class12.
The details (rno, name, cls and mks) 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 inserts the record in the table
Student.
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="class12")
mycursor= ________________#Statement 1
rno=int(input("Enter Roll Number :: "))
name=input("Enter name :: ")
cls=int(input("Enter class :: "))
mks=int(input("Enter Marks :: "))
querry="insert into student values({},'{}',{},{})".format(rno,name,cls,marks)
____________________#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)
OR
a. Predict the output of the following program
X = 100
def Change(P=10, Q=25):
global X
if P%6==0:
X+=100
else:
X+=50
print(P,'#',Q,'$')
Change()
Change(18,50)
Ans :
10 # 25 $
18 # 50 $
( 1 mark for each line)
b. The code given below reads the following record from the table named Book and
displays only those records with the book price greater than 250 rs.:
BNo – integer
BName – string
BPrice – integer
Statement 3- to read the complete result of the query (records of books priced
greater than 250rs.) into the object named content from the table
book.
import mysql.connector as ms
def book_data():
con1=ms.connect(host="localhost", user="root",password="tiger",
database="library")
mycursor= #Statement 1
print("Books priced greater than rs.250 are :")
_______________________ #Statement 2
content = #Statement 3
for i in content:
print(i)
print()
Ans:
Statement 1: con1.cursor()
Statement 2: mycursor.execute("select * from book where BPrice >250")
Statement 3: mycursor.fetchall()
33. Write differences in the file opening mode “a” and “w”? 5
def ShowRec():
with open(“CAPITAL.CSV”,”r”) as NF:
NewReader=csv.reader
c=0
for rec in NewReader:
print(rec[0],rec[1])
c=c+1
print( c)
Ans :
import pickle
def addrec():
fobj=open("STUDENT.dat","ab")
AdmnNo=int(input("Admission Number : "))
StdName=input("Name :")
Per = input("Percentage:" )
rec=[AdmnNo,StdName,Per]
pickle.dump(rec,fobj)
fobj.close()
countRec():
fobj=open("STUDENT.DAT","rb")
num = 0
try:
while True:
rec=pickle.load(fobj)
if rec[2] > 75:
print(rec[0],rec[1],rec[2],sep="\t")
num = num + 1
except: fobj.close()
return num
34. Prashanth has created a database for all the items available in his shop as interiors.
Table : Interiors 4
35. Preethi Shah is learning to work with binary files in Python using a process
known pickling/ unpickling. Her teacher has given her the following
incomplete code, which is creating a binary file namely Mydata.dat and then
opens, reads and displays the content of this created file,
_______________ #fill_line1
sqlist = list( )
for k in range(10):
sqlist.append(k*k)
fout = ______________ #fill_line2A
_________________ #fill_line3
fout.close( )
fin = _______________ #fill_line2B
___________________ #fill_line4
fin.close( )
print (“Data from file :”, mylist)
Help her complete the above code as per the instructions given below:
a. Complete fill_line1 so that required python library becomes available to
the program
b. Complete fill_line2A so that the above-mentioned binary file is opened
for writing in the file object fout
c. Similarly complete fill_line2B, which will open the same binary file for
sending in the file object fin.
d. Complete fill_line3 so that the list created in the code, namely sqlist, is
written in the open file.
e. Complete fill_line4 so that the contents of the open file in the file handle
fin are read in a list namely mylist.
Ans:
import pickle
Sqlist = list()
for k in range (10):
sqlist.append(k*k)
fout = open(“mydata.dat”,’wb’)
pickle.dump(sqlist,fout)
fout.close( )
fin=open(“mydata.dat”,’rb’)
mylist = pickle.load(fin)
fin.close( )
print(“Data from file:”, mylist)
(fill_line1 -1Mark
fill_line2A and fill_line2B – ½ mark each
fill_line3 – 1 mark
fill_line4 – 1 mark)