Analyze the following Python program that demonstrates connectivity between…

PYQ EMRS TGT/PGT (ESSE) 2025

Analyze the following Python program that demonstrates connectivity between Python and a MySQL database.
The program is designed to display all the rows (records) from a table named MYCONTACTS in the PHONEBOOK database, along with the total number of rows present in the table. An appropriate connectivity module has been correctly installed and is functioning properly. Some object and method/function names are missing from the code.

import mysql.connector as SQL        # Line 01

MyDB = SQL.connect(host='localhost', user='root',
                   password='bharat',
                   database='PHONEBOOK')            # Line 02

MyCursor = __A1__.__A2__             # Line 03

__B1__.__B2__("SELECT * FROM MYCONTACTS;")   # Line 04

print('Name\t\t Phone')                # Line 05

AllRow = __C1__.__C2__               # Line 06

for aRow in AllRow:                  # Line 07
    print(aRow[0], '\t\t', aRow[1])  # Line 08

print('\nTotal rows:', __D1__.__D2__)  # Line 09

Identify the correct missing components so that the program becomes complete and executes successfully.

Questions:

(A) Write the name of the object (A1) and method/function (A2) required to create the cursor object in Line 03.

(B) Write the name of the object (B1) and method/function (B2) required to execute the MySQL query in Line 04.

(C) Write the name of the object (C1) and method/function (C2) required to fetch all rows/records into the identifier AllRow in Line 06.

(D) Write the name of the object (D1) and method/function (D2) required to obtain the total number of rows/records in Line 09.

Attempted by 79 students.

Sign up free to check your answer

Sign up free

Explore the full course: Emrs Cs Tier 2

Loading lesson…