Test Index
CBSE Class 12 Computer Science 2023 Paper Compartment
© examsnet.com
Question : 32 of 35
Marks:
+1,
-0
(a) (i) What possible output(s) are expected to be displayed on screen at the time of execution of the following code ? (2)
import randomS=["Pen","Pencil","Eraser","Bag","Book"]for i in range (1,2): f=random.randint(i,3) s=random.randint(i+1,4) print(S[f],S[s],sep=":")Options :(I)
Pencil:Book(II) Pencil:BookEraser:Bag(III) Pen:BookBag:Book(IV) Bag:Eraser(ii) The table Bookshop in MySQL contains the following attributes :B_code – IntegerB_name – StringQty – IntegerPrice – IntegerNote the following to establish connectivity between Python and MySQL on a ‘localhost’ :• Username is ‘shop’• Password is ‘Book’• The table exists in a MySQL database named Bstore.The code given below updates the records from the table Bookshop in MySQL. (3)Statement 1 – to form the cursor object.Statement 2 – to execute the query that updates the Qty to 20 of the records whose B_code is 105 in the table.Statement 3 – to make the changes permanent in the database.import mysql.connector as mysqldef update_book(): mydb=mysql.connect(host="localhost", user="shop",passwd="Book",database="Bstore") mycursor=__________ # Statement 1 qry= "update Bookshop set Qty=20 where B_code=105" ___________________ # Statement 2 ___________________ # Statement 3OR(b) (i) Predict the output of the code given below : (2)
text="LearningCS"L=len(text)ntext=""for i in range (0,L): if text[i].islower(): ntext=ntext+text[i].upper() elif text [i].isalnum(): ntext=ntext+text[i-1] else: ntext=ntext+'&&'print(ntext)(ii) The table
Bookshop in MySQL contains the following attributes :B_code – IntegerB_name – StringQty – IntegerPrice – IntegerNote the following to establish connectivity between Python and MySQL on a ‘localhost’ :• Username is ‘shop’• Password is ‘Book’• The table exists in a MySQL database named Bstore.The code given below reads the records from the table Bookshop and displays all the records : (3)Statement 1 – to form the cursor object.Statement 2 – to write the query to display all the records from the table.Statement 3 – to read the complete result of the query into the object named B_Details, from the table Bookshop in the database.import mysql.connector as mysqldef Display_book(): mydb=mysql.connect(host="localhost", user="shop",passwd="Book",database="Bstore") mycursor=___________ # Statement 1 mycursor.execute("_________") # Statement 2 B_Details=__________ # Statement 3for i in B_Details: print(i)
Go to Question: