Test Index

CBSE Class 12 Computer Science 2023 Paper Set 4 Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 32 of 35
Marks: +1, -0
(a) What possible output(s) are expected to be displayed on screen at the time of execution of the following program :
import random
M=[5,10,15,20,25,30]
for i in range(1,3):
first=random.randint(2,5)- 1
sec=random.randint(3,6)- 2
third=random.randint(1,4)
print(M[first],M[sec],M[third],sep="#")
(i)
10#25#15
20#25#25
(ii)
5#25#20
25#20#15
(iii)
30#20#20
20#25#25
(iv)
10#15#25#
15#20#10# [2]
(b) The code given below deletes the record from the table employee which contains the following record structure :
E_code - String
E_name - String
Sal - Integer
City - String
Note the following to establish connectivity between Python and MySQL :
• Username is root
• Password is root
• The table exists in a MySQL database named emp.
• The details (E_code,E_name,Sal,City) are the attributes of the table.
Write the following statements to complete the code :
Statement 1 – to import the desired library.
Statement 2 – to execute the command that deletes the record with E_code as ‘E101’.
Statement 3 – to delete the record permanently from the database.
import ___________ as mysql     # Statement 1
def delete( ) :
mydb=mysql.connect(host="localhost",user="root",
passwd="root",database="emp")
mycursor=mydb.cursor( )
___________________ # Statement 2
___________________ # Statement 3
print ("Record deleted")
[3]
OR
(a) Predict the output of the code given below :
def makenew(mystr):
newstr=""
count=0
for i in mystr:
if count%2!=0:
newstr=newstr+str(count)
else :
if i.lower():
newstr=newstr+i.upper()
else:
newstr=newstr+i
count+=1
print(newstr)
makenew("No@1")
[2]
(b) The code given below reads the following records from the table employee and displays only those records who have employees coming from city ‘Delhi’:
E_code - String
E_name - String
Sal - Integer
City - String
Note the following to establish connectivity between Python and MySQL :
• Username is root
• Password is root
• The table exists in a MySQL database named emp.
• The details (E_code,E_name,Sal,City) are the attributes of the table.
Write the following statements to complete the code :
Statement 1 – to import the desired library.
Statement 2 – to execute the query that fetches records of the employees coming from city ‘Delhi’.
Statement 3 – to read the complete data of the query (rows whose city is Delhi) into the object named details, from the table employee in the database.
import ______________ as mysql        # Statement 1
def display():
mydb=mysql.connect(host="localhost",user="root",
passwd="root",database="emp")
mycursor=mydb.cursor()
______________________________ # Statement 2
details = ______________________ # Statement 3
for i in details:
print (i)
[3]
Advertisements
Go to Question: