CS12 pa2 2023-24 ms
CS12 pa2 2023-24 ms
General Instructions:
1. This question paper contains five sections, Sections A to E.
2. All questions are compulsory.
3. Section A has 18 questions (1 to 18) carrying 01 mark each.
4. Section B has 07 Very Short Answer questions (19 to 25), carrying 02 marks each. Two internal
choices are given in this section.
5. Section C has 05 Short Answer questions (26 to 30), carrying 03 marks each. Three internal
choices are given in this section.
6. Section D has 02 questions (31 to 32) carrying 04 marks each. Q31 part c has choice.
7. Section E has 03 Long Answer questions (33 to 35), carrying 05 marks each. Two internal choices
are given in this section.
8. All programming questions are to be answered using Python Language only.
SECTION – A
[This section contains 1 marker question]
1. Name the Python Library modules which need to be imported to invoke the [1]
following functions:
(i) ceil() (ii) randrange()
Ans math, random
2. Which of the following statements will create a tuple? [1]
(a) Tp1 = (“a”, “b”)
(b) Tp1= (3) * 3
(c) Tp1[2] = (“a”, “b”)
(d) None of these
Ans. (a) Tp1 = (“a”, “b”)
3. [1]
What possible output(s) are expected to be displayed on screen at the time of execution of the
program from the following code? Also specify the minimum values that can be assigned to each
of the variables BEGIN and LAST.
import random
VALUES = [10, 20, 30, 40, 50, 60, 70, 80]
BEGIN = random.randint (1, 3)
LAST = random.randint(2, 4)
for I in range (BEGIN, LAST+1):
print (VALUES[I], end = "-")
(a) 30-40-50- (b) 10-20-30-40- (c) 30-40-50-60- (d) 30-40-50-60-70-
Ans
OUTPUT – (i) 30-40-50-
Minimum value of BEGIN: 1
Minimum value of LAST: 2
½ marks for correct option and ½ marks for writing the values of begin and last.
4. Find the output - [1]
>>>A = [17, 24, 15, 30]
1|Page
>>>A.insert( 2, 33)
>>>print ( A [-4])
a. 15
b. 33
c. 24
d. 30
Ans c. 24
5. Which of the following statement create a dictionary? [1]
a) d = { }
b) d = {“john”:40, “peter”:45}
c) d = (40 : “john”, 45 : “peter”}
d) d = All of the mentioned above
Ans d) d = All of the mentioned above
6. The correct syntax of read() function from text files is: [1]
a. file_object.read()
b. file_object(read)
c. read(file_object)
d. file_object().read
Ans file_object.read()
7. What will the following expression be evaluated to in Python? [1]
10*1*2**4-4//4
Ans 159
8. Select the correct output of the following code : [1]
s=“I#N#F#O#R#M#A#T#I#C#S”
L=list(s.split(‘#’))
print(L)
a) [I#N#F#O#R#M#A#T#I#C#S]
b) [‘I’, ‘N’, ‘F’, ‘O’, ‘R’, ‘M’, ‘A’, ‘T’, ‘I’, ‘C’, ‘S’]
c) [‘I N F O R M A T I C S’]
d) [‘INFORMATICS’]
Ans (b) [‘I’, ‘N’, ‘F’, ‘O’, ‘R’, ‘M’, ‘A’, ‘T’, ‘I’, ‘C’, ‘S’]
9. Which of the following are the modes of both writing and reading in binary format in file? [1]
a) wb+
b) w
c) w+
d) wb
Ans a) wb+
10. To establish a connection with MySQL from Python which of the following functions is used? [1]
(a) connection() (b) connect() (c) open() (d) cursor()
Ans connect()
11. Fill in the blank [1]
_____________ command is used to modify the attribute datatype or size in a table
structure.
a) update b) alter c) insert d) None of these
Ans b) alter
12. Which of the following clause is used to sort records in a table? [1]
a) GROUP
b) GROUP BY
c) ORDER BY
d) ORDER
Ans c) ORDER BY
2|Page
13. Fill in the blank: [1]
_________ constraint is used to restrict entries in other table’s non key attribute, whose
values are not existing in the primary key of reference table..
a) Primary Key
b) Foreign Key
c) Candidate Key
d) Alternate Key
Ans b) Foreign Key
14. Fill in the blank: [1]
_______________ define rules regarding the values allowed in columns and is the standard
mechanism for enforcing database integrity.
a) Attribute
b) Constraint
c) Index
d) Commit
Ans b) Constraint
15. To create a connection between MYSQL database and Python application connect() function is [1]
used. Which of the following are mandatory arguments required to connect any database
from Python.
a) Username, Password, Hostname, Database Name, Port
b) Username, Password, Hostname
c) Username, Password, Hostname, Database Name
d) Username, Password, Hostname, Port
Ans c) Username, Password, Hostname, Database Name
16. Fill in the Blank [1]
________________ is the networking device that connects computers in a network by using
packet switching to receive, and forward data to the destination.
a) Switch b) Hub c) Repeater d) Router
Ans a) Switch
Q17 and 18 are ASSERTION AND REASONING based questions. Mark the correct
choice as:
(a) Both A and R 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 but R is False
(d) A is false but R is True
17. Assertion (A): Global variable is declared outside the all the functions. [1]
Reasoning (R): It is accessible through out all the functions.
18. Assertion (A): Binary files store all data in text format. [1]
Reasoning (R): Binary files data remain in its original type.
SECTION – B
[This section contains 2 marker questions and has 02 internal choice questions]
19. Predict the output of the following code: [2]
3|Page
OR
Ans
U * i * e * Nations a * i * n *
OR
vELCcME#Kk [2 mark for correct output]
20. a. Find output generated by the following code: [2]
mystr = “Hello I am a Human.”
print(mystr[::-3])
b. Write the output of the code given below:
p=10
q=20
p*=q//3
p=q**2
q+=p
print(p,q)
Ans
(a) .m mIlH
(b) 400 420
[2 mark for correct output]
21. Rajat has written the following Python code. There are some errors in it. Rewrite the correct code and [2]
underline the corrections made.
4|Page
22. What is the difference between absolute and relative positioning in random method of binary file? [2]
Ans
Python file method seek() sets the file's current position at the offset. The whence argument is
optional and defaults to 0, which means absolute file positioning, other values are 1 which means
seek relative to the current position and 2 means seek relative to the file's end
[1 marks for each point]
23. Answer the following: [2]
i) Name the package imported for connecting Python with MySQL database.
ii) What is the purpose of cursor object?
OR
i) Difference between candidate key and alternate key? Give an example.
Ans
i) mysql.connector
ii) Cursor object is used to interact with MySQL connection object from Python code
[1 mark for each part]
OR
i) Candidate key - A candidate key is a set of columns that uniquely identify rows in a
table. Candidate keys are important for database design because they help ensure
data integrity and uniqueness, and they facilitate efficient retrieval of data. Every
table must have at least one candidate key, and the columns in a candidate key
are called prime attributes.
Alternate key - An alternate key is a candidate key that is not selected as the
primary key. Alternate keys provide a secondary means of identifying records in a
table. All the columns in a table other than the primary key act as alternate keys
for that table.
[1 mark for definition and 1 mark for example]
24. Differentiate between DDL and DML with one Example each. [2]
Ans DDL- Data definition language. Consists of commands used to modify the schema/metadata of a table.
For Example- create table, alter table, drop table.
DML-Data manipulation language. Consist of commands used to modify the data of a table. For Example-
insert, delete, update
[1 mark for definition and 1 mark for example]
25. a. Give the full form of the following: [2]
i. SMTP
ii. IMAP
b. What is the use of HTTP?
Ans a. URL: Simple Mail Transfer Protocol, IMAP: Internet Message Access Protocol
b. HTTP protocol is used to transmit hypermedia documents like HTML over the internet
[1 mark for each part]
SECTION – C
[This section contains 3 marker questions and has 03 internal choice questions]
5|Page
26. Write a function in python to read lines from file “POEM.txt” and display all those words, which has two [3]
characters in it.
Ans
OR
Write a function count1() in python to read contents from a text file REPEATED.TXT and display those lines
which have occurrence of the word ‘‘CATHOLIC’’ or ‘‘mother’’.
For e.g. Suppose the content is
6|Page
Ans
def oddeve(myList):
print("All positive numbers of the list : ")
for ele in myList:
if ele >= 0:
print(ele, end = " ")
OR
def listchange(Arr,n):
for i in range(n):
if Arr[i]%2 == 0:
Arr[i] *= 2
else:
Arr[i] *= 3
mylist = [12,11,23,24]
listchange(mylist,4)
print(mylist)
28. i. What is the difference between parameter and argument? [2] [3]
ii. Explain LEGB Rule [1]
OR
i. What is the difference between pass by value and pass by reference?[2]
ii. What is the difference between local variable and nonlocal variable? [1]
Ans
i. A parameter is a variable in a function definition. It is a placeholder and hence does not
have a concrete value. An argument is a value passed during function invocation.
ii. The LEGB rule is a kind of name lookup procedure, which determines the order in which
Python looks up names. For example, if you reference a given name, then Python will look
that name up sequentially in the local, enclosing, global, and built-in scope. If the name
exists, then you'll get the first occurrence of it.
OR
i.
ii.
1. Local variable – The variables which are accessible only inside the functional block where it
is declared.
2. Non local variable – Accessible in nesting of functions, using nonlocal keyword
29. a. What is the usage of seek() and tell() function? [2] [3]
b. Explain the process of Serialization and De-Serialization. [1]
7|Page
Ans
a. The seek() function is used to set the position of the file cursor, whereas the tell() function
returns the position where the cursor is set to begin reading.
b. Serialization is the process of converting the state of an object to a byte stream.
Deserialization is the reverse of serialization and converts the byte stream back to the
original object.
30. (a) Consider the following tables – Uniform and Cost: [1] [3]
8|Page
SECTION – D
[This section contains 4 marker questions. Q31 has internal choice in C part Only]
31. A department is considering to maintain their worker data using SQL to store the data. As a database [1]+
administer, Karan has decided that : [1]+
Name of the database - Department Name of the table - WORKER [2]
The attributes of WORKER are as follows: WORKER_ID - character of size 3 FIRST_NAME – character of
size 10 LAST_NAME– character of size 10 SALARY - numeric
JOINING_DATE – Date
DEPARTMENT – character of size 10
9|Page
32. Aditya is a Python programmer. He has written a code and created a binary file student.dat with [1]+
rollno, name, class and marks. The file contains 10 records. He now has to search record based on [1]+
rollno in the file student.dat [2]
As a Python expert, help him to complete the following code based on
the requirement given above:
import _______ #Statement 1
def searchrec():
r=int(input('Enter roll no of student to be searched'))
f=open(______________________) # staement2
found=False
try:
while True:
data=_______________ # statement 3
for rec in data:
if r==_______: # staement4
found=True
print('Name: ',rec[1])
print('Class : ',rec[2])
print('marks :',rec[3])
break
except Exception:
f.close()
if found==True:
print('Search successful')
else:
print('Record not exist')
10 | P a g e
(b) Avni is trying to connect Python with MySQL for her project. Help her to write the python
statement on the following:
i. Name the library, which should be imported to connect MySQL with Python.
ii. Name the function, used to run SQL query in Python.
iii. Write Python statement of connect function having the arguments values as : Host name
:192.168.11.111 User : root Password: Admin Database : MYPROJECT
OR
(a) Find the output
b) Your friend Jagdish is writing a code to fetch data from a database Shop and table name Products
using Python. He has written incomplete code. You have to help him write complete code:
import __________ as m # Statement-1
object1 = m.connect(
host="localhost",
user="root",
password="root",
database="Shop"
)
object2 = object1._____ # Statement-2
query = '''SELECT * FROM Products WHERE NAME LIKE "A%";'''
object2._____(query) # Statement-3
object1.close()
Ans
a. exam$$*CBSE*COM
11 | P a g e
b.
i. import mysql.connector
ii. cursorobj.execute(query)
iii. mysql.connector.connect(host= “192.168.11.111”, user = “root”, passwd = “Admin”, database=
“MYPROJECT”)
OR
a.
1 20 X@
4 30 X@Y@
9 60 X@Y@Z@
b. Statement-1: mysql.connector
Statement-2: cursor()
Statement-3: execute
[2 marks for part A and 3 marks for part B]
34. Prithvi Training Institute is planning to set up its centre in Jaipur with four specialized blocks for Medicine, [5]
Management, Law courses along with an Admission block in separate buildings. The physical distances
between these blocks and the number of computers to be installed in these blocks are given below. You as a
network expert have to answer the queries raised by their board of directors as given in (i) to (v).
i. Suggest the most suitable location to install the main server of this institution to get efficient connectivity.
ii. Suggest by drawing the best cable layout for effective network connectivity of the blocks having server
with all the other blocks.
iii. Suggest the devices to be installed in each of these buildings for connecting computers installed within
the building out of the following:
Modem, Switch, Gateway, Router
iv. Suggest the most suitable wired medium for efficiently connecting each computer installed in every
building out of the following network cables: Coaxial Cable, Ethernet Cable, Single Pair, Telephone Cable
v. Suggest the type of network implemented here.
Ans
(i) Admin Block. Because of Maximum Computers.
(ii) Any Suitable layout
(iii) Switch
(iv) Ethernet cable
(v) LAN
35. Consider the following tables STOCK and DEALERS : [5]
12 | P a g e
Write SQL commands for the following statements:
(i) To display details of all Items in the Stock table whose amount is more than 5000.
Ans. SELECT * FROM STOCK where (qty*unitprice)>5000;
(ii) To display ItemNo and Item name of those items from Stock table whose UnitPrice is more than`
10 and stock date before 2010-01-01
Ans. SELECT ItemNo, Item FROM STOCK WHERE UnitPrice>10 and stockdate<”2010-01-01”;
(iii) To display the details of those items whose dealer code (Dcode) is 102 or Quantity in Stock (Qty)
is more than 100 from the table Stock.
Ans. SELECT * FROM STOCK WHERE Dcode=102 OR Qty>100;
(iv) To display Maximum UnitPrice of items for each dealer individually as per Dcode from the table
Stock.
Ans. SELECT Dcode, MAX (UnitPrice) FROM STOCK GROUP BY Dcode;
(i) To display item and amount where dealer name are reliable stationers or classic plastics (where
amount = qty*price)
13 | P a g e
i. Identify the most appropriate column, which can be considered as Primary key. [1]
Ans: ROLL_NO
(1 mark for correct answer)
ii. If two columns are added and 2 rows are deleted from the table result, what will be the new degree and
cardinality of the above table? [1]
Ans:
New Degree: 8
New Cardinality: 5
(1/2 mark for correct degree and ½ mark for correct cardinality)
iii. Write the statements to: [3]
a. Increase the SEM2 marks of the students by 3% whose name begins with ‘N’.
b. Delete the record of students securing IV division.
c. Add a column REMARKS in the table with datatype as varchar with 50 characters
Ans:
a. UPDATE RESULT SET SEM2=SEM2+ (SEM2*0.03) WHERE SNAME LIKE “N%”;
b. DELETE FROM RESULT WHERE DIV=’IV’;
c. ALTER TABLE RESULT ADD (REMARKS VARCHAR(50));
(1 mark for each correct statement)
14 | P a g e