INTERFACE
INTERFACE
5 The code given below inserts the following record in the table Student:
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is tiger
The table exists in a MYSQL database named school.
The details (RollNo, Name, Clas and Marks) are to be accepted from the user.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table
Student.
Statement 3- to add the record permanently in the database
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="root",password="tiger",
database="school")
mycursor=_________________ #Statement 1
rno=int(input("Enter Roll Number :: "))
name=input("Enter name :: ")
clas=int(input("Enter class :: "))
marks=int(input("Enter Marks :: "))
querry="insert into student values({},'{}',{},{})".format(rno,name,clas,marks)
______________________ #Statement 2
______________________ # Statement 3
print("Data Added successfully")
6 The code given below reads the following record from the table named student
and displays only those records who have marks greater than 75:
RollNo – integer
Name – string
Clas – integer
Marks – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is tiger
The table exists in a MYSQL database named school.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the query that extracts records of those students
whose marks are greater than 75.
Statement 3- to read the complete result of the query (records whose
marks are greater than 75) into the object named data, from the table student in
the database.
import mysql.connector as mysql
def sql_data():
con1=mysql.connect(host="localhost",user="root",password="tiger",
database="school")
mycursor=_______________ #Statement 1
print("Students with marks greater than 75 are : ")
_________________________ #Statement 2
data=__________________ #Statement 3
for i in data:
print(i)
print()
7 The code given below inserts the following record in the table Employee:
Empno – integer
EName – string
Desig – integer
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is Password
The table exists in a MYSQL database named Bank.
The details (Empno, Ename, Design and Salary) are to be accepted from the
user.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to query string.
Statement 3- to execute insert query for employee table
import mysql.connector
mydb=mysql.connector.connect(host='localhost',user='root',passwd='Password',
database='bank')
mycursor=_________________ # statement1
eno=int(input('enter Employee no'))
nm=input('enter Employee name')
d=input('enter Designation)
s=int(input(‘Enter salary’))
rtup=(eno,n,d,s)
8 The code given below reads the following record from Table named Employee
and display those record salary >= 30000 and <= 90000:
Empno – integer
EName – string
Desig – integer
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is Password
The table exists in a MYSQL database named Bank.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to query string.
Statement 3- to execute the query that extracts records of those Employees
whose salary >=30000 and <=90000.
import mysql.connector
mydb=mysql.connector.connect(host='localhost',user='root',passwd='Password',
database='bank')
mycursor=_________________ # statement1
mycursor.________________ #statement 2
data= __________________ # statement 3
for x in data:
print(x)