0% found this document useful (0 votes)
33 views8 pages

Class12 Mock Test-1 2024 Solution

The document discusses a mock test for a computer science exam. It contains questions about Python, SQL, networking and other computer science topics. It provides the questions, answers, and explanations for multiple choice, code writing and other types of questions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views8 pages

Class12 Mock Test-1 2024 Solution

The document discusses a mock test for a computer science exam. It contains questions about Python, SQL, networking and other computer science topics. It provides the questions, answers, and explanations for multiple choice, code writing and other types of questions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Class: XII Computer Science (2024)

Mock Test-1 | SOLUTION


Section-A
1. Find the invalid identifier(s) from the following 1
a) Float b) Pass c) None d) True
Ans: c, d
2. Name the default delimiter character to separate values in a .csv file. 1
Ans: Comma
3. Identify the valid relational operators in Python from the following: 1
a) => b) != c) <= d) *=
Ans: b, c
4. Consider the following code and choose the correct option: 1
T = (5)
print( len(T) )
a) 1 b) 0 c) None d) Error
Ans: d
5. Write a statement in Python to declare a dictionary from two lists. The keys 1
are [1, 2, 3] and values are [‘Monday’, ‘Tuesday’, ‘Wednesday’] respectively.
Ans: D = dict ( zip ( [1, 2, 3], [‘Monday’, ‘Tuesday’, ‘Wednesday’] ) )
6. None is a special literal in Python that represents nothing. 1

7. What will be the output if the following code is executed? 1


name = "ComputerScienceWithPython"
print( name [ :10:2] )
Ans: CmueS
8. Name the protocol that is used to send or receive files through Internet. 1
Ans: FTP or File Transfer Protocol
9. Write the full form of UTP. 1
Ans: Unshielded Twisted Pair
10. By default, in which order does the ORDER BY clause print data? 1
Ans: Ascending (ASC)
11. What is the use of the LIKE operator in SQL? 1
Ans: The LIKE operator is used to compare parts of a string in an SQL query.
12. Which of the following is an invalid aggregate function in SQL? 1
a) max b) sum c) average d) count
Ans: c
13. Write the names of any two Data Definition Language commands in SQL. 1
Ans: Create, Alter
14. Write the names of any two types of cables used in networking. 1
Ans: UTP, Coaxial (Fibre Optic, STP also)
15. Identify the invalid declaration of a list L: 1
a) L = [‘one’, ‘two’] b) L = [(1,), (2,)] c) L = [{1:2}, {3:4}] d) L = List( )
Ans: d
16. Which of the following line(s) is/are incorrect? 1
L=[ 1, 2, 3, 4, 5 ] # Line 1
print( L[-4:4] ) # Line 2
P = 2*L # Line 3
S = P[::-1] # Line 4
S.insert(15,20) # Line 5
print( S ) # Line 6
(a) Line 2 (b) Line 3 (c) Line 3 & 5 (d) None of the lines
Ans: d
Pg-1
17. Name the module that is to be imported to connect Python with MySQL. 1
Ans: mysql.connector
18. Name the SQL command that can be used to list all the tables in a given 1
database.
Ans: show tables;
Section-B
19. Evaluate the following expressions: 2
a) 2**4 // 2 ** 3 + 100 % 5
b) 2 > 4 or 2 < 3 and not 100 <= 54
Ans: a) 2 b) True
20 Rewrite the following code in Python after removing all syntax error(s). 2
Underline each correction done in the code.
to = 20
for j in range(0, to)
if j%4=0:
print (j*4)
Else:
print (j+3)
Ans:
to = 20
for j in range(0, to) :
if j%4 == 0:
print (j*4)
else:
print (j+3)
21 Expand the following terms: 2
a. NIC b. URL c. DNS d. FTP
a) Network Interface Card
b) Uniform Resource Locator
c) Domain Name System
d) File Transfer Protocol
22 (a) Write the output of the following Python code: 2
disease = "pneumonoultramicroscopicsilicovolcanoconiosis"
print( disease.split('c')[2::2] )
Ans: ['opi', 'ovol', 'oniosis']
(b) Write the output of the following Python code:
L1 = ["red", "green", "blue"]
L2 = L1
L1.remove("red")
L2.remove("blue")
print(L1)
Ans: ['green']

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()

28 A Fitness Gym is considering to maintain their database using SQL. As a 22


database administrator, Sunil has decided the following:
• Name of the database - FitGym
• Name of the table - Members
• The attributes of table Members (shown below) are as follows:
Mem_No – character of size 3
Mem_Name – character of size 20
City – character of size 20
Age – numeric
Fees – numeric
Members
Mem_No Mem_Name City Age Fees
M01 Rajiv Kolkata 29 400
M02 Sikha Kolkata 25 460
M03 Amit Howrah 20 420

a) Identify the attribute best suitable to be declared as a primary key


Ans: Mem_No
b) Insert the following data into the given table Members:
Mem_No = M04, Mem_Name = Ajit, City = Kolkata, Age = 26, Fees = 400
Ans: insert into Members values (‘M04’, ‘Ajit’, ‘Kolkata’, 26, 400);
c) Write the code to insert a new column called Phone in the Member table.
Ans: alter table member add phone char(10);
d) Write the degree and cardinality of the table Members after the above row
is inserted in the current table as shown above
Ans: Degree=5, Cardinality=4 (not considering question c)
e) Arrange and display the records of the Members table in descending
alphabetical order of Mem_Name
Ans: select * from Members order by Mem_Name desc;
f) Once you have opened MySQL, write the command to enter or work with
the FitGym database.
Ans: use FitGym;

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

D29 Indra Sen MWF 2011-03-25 2

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

c) Which device will you suggest to be placed/installed in each of these


wings to efficiently connect all the computers within these wings?
Ans: Switch
d) The company wants internet accessibility in all the wings. Suggest a
suitable technology.
Ans: A proxy server placed in the server wing W1 can be used to provide
internet connectivity to all the wings.
e) The company is planning to link its head office in Gurgaon with these
wings which are located in a hilly area at a distance of 1230 Km from
Gurgaon. Suggest a way to connect this economically.
Ans: As distance is very large, it will be costly to lay cables. Hence wireless
connectivity can be used. Either radio connectivity or satellite communication
can be used.
34 Define a function newConnection( ) in Python to accept new data from the 5
user and add it to a file ‘NewCon.dat’, for those data where area code is
700019. Assume that the binary file ‘NewCon.dat’, is an existing file with
more than 500 records and contains data in the form of lists like:
Tele = [ 24405112, ‘Amit Sen’, 700033].
Here the first list element is a phone number, the second element is the
customer’s name and the third element is the PIN code of the customer.

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

You might also like