Test Index
CBSE Class 12 Computer Science 2023 Paper Set 4
© 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 randomM=[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#1520#25#25(ii)5#25#2025#20#15(iii)30#20#2020#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 - StringE_name - StringSal - IntegerCity - StringNote 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 1def 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 - StringE_name - StringSal - IntegerCity - StringNote 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 1def 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]
Go to Question: