Practical Programs
Practical Programs
Write a Menu Driven Python program to find Factorial and Sum of List of
numbers Using Function.
b. Write a program to create a text file’ABC.txt’ and print the count of words,
digits and no of lines
The code given below inserts the following record in the table "Students":
Rollno - integer, Name- string , Age –integer, Percentage - integer
Note the following to establish connectivity between Python and MYSQL:
Username: root
Password: root
The table exists in a MYSQL data base named "School".
The details (Roll no, Name, Age, Percentage) are to be accepted from
the user.
import ___________________ as sql # Statement 1
con1=sql.connect(host="localhost",user="root",password="root",
database="school")
mycursor=_______________ #Statement 2
print("Students with Percentage greater than 75 are : ")
_________________________ #Statement 3
data=__________________ #Statement 4
for i in data:
print(i)
print()
con1.close()
(a)Complete the Statement 1 by writing the name of library/Package need to
import for database.
(b)Complete the Statement 2 to form the cursor object.
(c) Complete the Statement 3 to by writing the execution query that extracts
records of those students whose Percentage is greater than 75.
(d)Complete the Statement 4 to read the complete result of the query
(records whose Percentage is greater than 75) into the object named data,
from the table student in the database.
Q.1 Write a menu driven python program to create a data file ‘emp.dat’ that
collects 5 employees’ data (name, id, salary, designation). Read all the data and
update the salary of all the managers by adding 5000.
(Menu: Create, Display, Update,Exit)
The code given below inserts the following record in the table "EMP":
EmpId - integer, Name- string , Salary –integer.
Note the following to establish connectivity between Python and MYSQL:
Username: root
Password: root123
The table exists in a MYSQL data base named "Employees".
The details (EmpId, Name and Salary) are to be accepted from the user.
import ___________________ as sql # Statement 1
con=sql.connect(host="localhost",user="root",password="root123",
database="Employees")
eno=int(input("Enter Employee ID : "))
name=input("Enter name : ")
sal=int(input("Enter Salary : "))
cur=______________________ # Statement 2
Q=______________________ # Statement 3
cur.execute(Q)
con._______________ #Statement 4
print("Employee Details are stored Successfully")
con.close()
The code given below inserts the following record in the table "Books".
BookId - integer, PName- string , Price –integer, Author - string
Note the following to establish connectivity between Python and MYSQL:
Username: root
Password: root@123
The table exists in a MYSQL data base named "Bookshop".
The details (Bookid, BName, Price, Author) are to be accepted from the
user.
Q.1 Write a Python Program to Create a binary file "Students.dat" to store roll
number, name and Search for a given roll number and display the details , if
not found display appropriate message.
(Menu: Create , Read, Search, Exit)
The code given below inserts the following record in the table "Books".
BookId - integer, PName- string , Price –integer, Author - string
Note the following to establish connectivity between Python and MYSQL:
Username: root
Password: root@123
The table exists in a MYSQL data base named "Bookshop".
The details (Bookid, BName, Price, Author) are to be accepted from the
user.
The code given below inserts the following record in the table Trainer.
TId - integer, TName- string , City – String, DOJ - Date
Note the following to establish connectivity between Python and MYSQL:
Username: root
Password: trainer@123
The table exists in a MYSQL data base named "Company".
The details (Tid, TName, City, DOJ) are to be accepted from the user.
The code given below inserts the following record in the table "Graduate":
SId - integer, SName- string , Stipend – integer, Dept- string
Note the following to establish connectivity between Python and MYSQL:
Username: root
Password: root
The table exists in a MYSQL data base named "University".
The details (Sid, SName, Stipend, and Dept) are to be accepted from the
user.
(Hint: Push the names of the book only if the price is greater than 300 otherwise ask
for the book details again.
The code given below inserts the following record in the table "Library":
CDNO - integer, Name- string , Qty – integer, Price – integer.
Note the following to establish connectivity between Python and MYSQL:
Username: root
Password: root
The table exists in a MYSQL data base named "School".
The details (CDNO, Name, Qty, Price) are to be accepted from the user.
LIBRARY
CDNO NAME QTY PRICE
1001 Patriotic 20 200
1002 Regional 17 100
1003 Praises of Land 20 130
1004 Hindustani 12 NULL
1005 Arabic 18 NULL
Write a menu driven pyhon program to sort the given list using both Bubble Sort and
Insertion Sort.
The code given below inserts the following record in the table "EMPLOYEE":
EId - integer, Ename- string , Salary – integer, Dept- string
Note the following to establish connectivity between Python and MYSQL:
Username: root
Password: root
The table exists in a MYSQL data base named "Tech".
The details (Sid, SName, Stipend, and Dept) are to be accepted from the
user.
The code given below inserts the following record in the table "Students":
Rollno - integer, Name- string , Age –integer, Percentage - integer
Note the following to establish connectivity between Python and MYSQL:
Username: root
Password: root
The table exists in a MYSQL data base named "School".
The details (Roll no, Name, Age, Percentage) are to be accepted from
the user.
import ___________________ as sql # Statement 1
con1=sql.connect(host="localhost",user="root",password="root",
database="school")
mycursor=_______________ #Statement 2
print("Students with Percentage greater than 75 are : ")
_________________________ #Statement 3
data=__________________ #Statement 4
for i in data:
print(i)
print()
con1.close()
(a) Complete the Statement 1 by writing the name of library/Package need
to import for database.
(b) Complete the Statement 2 to form the cursor object.
c) Complete the Statement 3 to by writing the execution query that extracts
records of those students whose Percentage is greater than 75.
d) Complete the Statement 4 to read the complete result of the query (records whose
Percentage is greater than 75) into the object named data, from the table student in
the database.