Class12 Mock Test-1 2024 Solution
Class12 Mock Test-1 2024 Solution
Pg-2
23 What possible outputs(s) are expected to be displayed on screen at the time of 2
execution of the program from the following code? Also specify the maximum
values that can be assigned to each of the variables Beg and End.
import random
Score = [11, 22, 33, 44, 55]
Beg = random.randint(1, 3)
End = random.randint(2, 4)
for c in range(Beg, End):
print (Score[c], end = '#')
(i) 11#22#33# (ii) 22#33#44# (iii) 22#33# (iv) 33#44#
Ans: (ii), (iii), (iv)
Maximum value of Beg = 3. Maximum value of End = 4
24 Differentiate between Primary Key and Alternate Key with suitable example. 2
Ans: A table may have more than one set of attributes that have unique values and
can be used to form a primary key. In that case any one of them is chosen to form
the primary key. The remaining keys are called Alternate Keys.
25 Assuming that NUM is a list of numbers, write a function in Python called 2
change(NUM), to divide all the elements of the list by 10 which are divisible
by 5 and multiply the other list elements by 2. Element of a list may change
to a float as a result of the division by 10.
Ans:
def change(NUM):
for i in range( len(NUM) ):
if NUM[i]%5 == 0:
NUM[i] = NUM[i]/10
else:
NUM[i] *= 2
print(NUM)
Section-C
26 Find and write the output of the following Python code: 3
def assign( L1, L2, L3):
for i in range(1, 11, 2):
L1.append(i)
for j in range(2, 11, 2):
L2.append(j)
for k in range(0, 5):
L3.append( L1[k] + L2[k] )
#main
L1, L2, L3 = [ ], [ ], [ ]
assign( L1, L2, L3 )
print(L1, L2, L3)
Ans: [1, 3, 5, 7, 9] [2, 4, 6, 8, 10] [3, 7, 11, 15, 19]
Pg-3
27 Write a function in Python to read a text file ‘poem.txt’ and count and print 3
the number of lines that start with T or I. For example, for the file content:
The sound of silence
Inside the jail corridors
Was almost unbearable
To bare with.
The output of the function should be: Count of lines is 3
Ans:
def startLine():
fin = open('poem.txt', 'r')
c=0
while True:
s = fin.readline()
if s == "":
break
if s[0] in 'TI':
c += 1
print('Count of lines is ', c)
fin.close()
Pg-4
29 Write the outputs of the SQL queries (i) to (iii) based on the relations Doctor 3
and Department given below:
Doctor Department
ID DName OPD_Days DOJ Dp_ID Dp_ID DpName
D12 Shyamal De TWT 2008-02-15 1 1 Cardiac
D15 Avik Kundu SMT 2005-05-19 3 2 Neuro
D19 Bikash Roy TWT 2018-03-12 1 3 Medicine
D23 Shrea Das FSS 2010-02-13 2
D25 Dilip De SMT 2009-06-10 1
i. select ID, DName, OPD_Days, from Doctor where Dp_ID not in (1, 3);
Ans:
ID DName OPD_Days
D23 Shrea Das FSS
D29 Indra Sen MWF
ii. select count(*) as DpCount from Doctor where Dp_ID = 1;
Ans:
DpCount
3
iii. select DName, DpName from Doctor, Department
where Doctor.Dp_ID = Department.Dp_ID;
Ans:
DName DpName
Shyamal De Cardiac
Avik Kundu Medicine
Bikash Roy Cardiac
Shrea Das Neuro
Dilip De Cardiac
Indra Sen Neuro
30 A list CarList contains following data as list elements: [Name, Make, Price] 3
Here Name is the name of a car, Make is name of the car manufacturer, and Price is
the price of the car in lakhs (thus 8.2 means 8.2 lakhs). Each of these lists are put
together to form a nested list of different cars. Write the following user defined
functions in Python to perform the specified operations on a stack named CAR.
PUSH(AllCarList): It takes the nested list called AllCarList as an argument and
creates a new list with name and price of the car corresponding to the car
manufacturer named ‘Suzuki’. It then pushes those lists into the stack.
POP( ): It pops the objects from the stack and displays the car name for all cars
priced below 10 lakhs. Also, the function should display 'Stack Empty' when there
are no elements left in the stack during pop.
Ans:
CAR = [ ]
def PUSH(AllCarList):
for L in AllCarList:
if L[1] == 'Suzuki':
NewL = [ L[0], L[2] ]
CAR.append( NewL )
def POP( ):
while len(CAR) != 0:
L = CAR.pop()
if L[1] < 10:
print ( L[0] )
print ('Empty Stack')
Pg-5
Section-D
31. Based on the database tables Doctor and Department in question 29, write
SQL queries for the following:
(i) Display the names of doctors whose name starts with letter S or I.
select dname from doctor where dname like 'S%' or dname like 'I%';
(ii) Display department names in descending order of DpName.
select dpname from department order by dpname desc;
(iii) Display the maximum and minimum fees of doctors with Dp_ID=1.
select max(fees), min(fees) from doctor where dp_id = 1;
(iv) Display the description of the table Doctor.
describe doctor; or desc doctor;
32. Write a Python Program to define and call the following user defined functions:
Save( ): To accept and add a single circus related data of type dictionary to a
binary file ‘circus.dat’. The function receives as argument the data for a given
circus as a dictionary like {“name”:“Gemini”, “items”:12 “ticket”:150.00} and
writes it to the binary file.
Display( ): To read the ‘circus.dat’ file and display the names of those
circuses where the number of items performed is more than 10.
import pickle
def Save( D ):
fout = open (‘circus.dat’, ‘ab’)
pickle.dump(D)
fout.close()
def Display( ):
fin = open (‘circus.dat’, ‘rb’)
try:
while True:
D = pickle.load(fin)
if D[‘items’] > 10:
print(D[‘name’])
except:
fin.close()
#main:
D={}
D[‘name’] = input(‘Enter name:’)
D[‘items’] = int(input(‘Enter number of items:’))
D[‘ticket’] = float(input(‘Enter ticket price:’))
Save( D )
Display()
Section-E
33 A company has 4 wings of buildings as shown in the diagram below: 5
W1 W2
W3 W4
Pg-6
Distance in metres between various wings is as follows:
W3 – W1 50
W1 – W2 60
W2 – W4 25
W4 – W3 170
W3 – W2 125
W1 – W4 90
Number of computers:
W1 80
W2 15
W3 15
W4 25
a) Suggest the most suitable wing to install the server of this company with
a suitable reason.
Ans: As the wing W1 has the largest number of computers hence as per the 80-
20 rule the server is to be placed in wing W1
b) Suggest an ideal layout for connecting these wings for a wired
connectivity.
Ans: Option-1 (Maximum efficiency) Option-2 (Minimum cable length)
60 60
W1 W2 W1 W2
50 90 50 25
W3 W4 W3 W4
Pg-7
Ans:
import pickle
def newConnection():
fout = open('NewCon.dat', 'ab')
ph = int(input('Enter phone number: '))
cn = input('Enter customer name: ')
pin = int(input('Enter pincode: '))
if pin == 700019:
L = [ph, cn, pin]
pickle.dump(L, fout)
fout.close( )
OR
import pickle
def newConnection():
with open('NewCon.dat', 'ab') as fout:
ph = int(input('Enter phone number: '))
cn = input('Enter customer name: ')
pin = int(input('Enter pincode: '))
if pin == 700019:
L = [ph, cn, pin]
pickle.dump(L, fout)
35 4
a) What do you mean by absolute path of a file?
The absolute path of a file is the location of the file with respect to the drive and the
folders under which the file is located. Example of an absolute path:
D:\works\programs\prog1.py
b) The code given below updates the teacher’s name from table CCA (that stores
data about co-curricular activities) against a given CCA#, where each record
stores the following data: (CCA#, Subject, Teacher)
Note the following to establish connectivity between Python and MYSQL:
• Host is 'localhost' • Username is 'root'
• Password is 'cc@314' • Database used 'SCHOOL'
Write the following missing statements to complete the code:
Statement1 – imports necessary module for connectivity
Statement2 – creates a cursor object
Statement3 – forms the formatted query string to execute
import mysql.connector as scon #Statement1
def updateRow():
pcon = scon.connect(host="localhost", user="root", \
passwd="cc@314", database='SCHOOL')
ccc = pcon.cursor() #Statement2
CC = int(input("Enter CCA number of record to update: "))
TC = input("Enter updated teacher name: ")
QUERY = "update CAA set teacher = '{}' where cc = '{}'".format(TC, CC)
#Statement3
ccc.execute(QUERY)
print("Record updated successfully")
pcon.commit()
pcon.close()
Pg-8