Q.(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="#")
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →First (a): random indices are all 1..4 so only option (i) is possible; delete code = import mysql.connector as mysql / mycursor.execute("DELETE FROM employee WHERE E_code='E101'") / mydb.commit(). Second (a): makenew("No@1") prints " N1@3" (leading space); fetch code = same import / mycursor.execute("SELECT * FROM employee WHERE City='Delhi'") / details = mycursor.fetchall().
Both alternatives are labelled (a) and each has an output-prediction part plus a Python-MySQL part.
Part (a)
First alternative.
(a) Possible output. With M=[5,10,15,20,25,30]:
first = random.randint(2,5) - 1yields 1,2,3 or 4.sec = random.randint(3,6) - 2yields 1,2,3 or 4.third = random.randint(1,4)yields 1,2,3 or 4.
Every index lies in 1..4, so only M[1]=10, M[2]=15, M[3]=20, M[4]=25 can be printed — never 5 (M[0]) or 30 (M[5]). The loop range(1,3) runs twice, giving two lines, and sep="#" puts # between the three items with no trailing #.
Evaluating the options: (i) 10#25#15 and 20#25#25 uses only allowed values and the right format → possible; (ii) contains 5 = M[0] → impossible; (iii) contains 30 = M[5] → impossible; (iv) has a trailing # → impossible. Only (i).
(b) Delete code. Connectivity uses mysql.connector; a DELETE ... WHERE removes the target row and commit() makes it permanent.
import mysql.connector as mysql # Statement 1
def delete():
mydb=mysql.connect(host="localhost",user="root",passwd="root",database="emp")
mycursor=mydb.cursor()
mycursor.execute("DELETE FROM employee WHERE E_code='E101'") # Statement 2
mydb.commit() # Statement 3
print("Record deleted") …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.