0% found this document useful (0 votes)
25 views9 pages

Practical Programs

Cs

Uploaded by

G SUGANYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Practical Programs

Cs

Uploaded by

G SUGANYA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Q.1 a.

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

Q.2 Complete the following Database connectivity program by writing missing


statements and perform the given query.
TABLE: Students
Roll Name Ag Percentag
e e
1 Arun 24 65
2 Ankit 21 71
3 Anu 20 80
4 Bala 19 67
5 Charan 18 95
6 Usha 23 82

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)

Q.2 Complete the following Database connectivity program by writing missing


statements and perform the given query.
TABLE: EMP
EmpId Name Salary
1001 Bass 50000
1002 Ryan 70000
1003 Anuj 55000
1004 Shumina 82000
1005 Leela 36000

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()

(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 by writing the query that Increase the Price of
the Books by 10% whose Price is more than 300.
(d)Complete the Statement 4 to execute the command that update the records
in the table Books
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)

Q.2 Complete the following Database connectivity program by writing missing


statements and perform the given query.
TABLE: Books
BookI BName Price Author
d
1001 Netiquettes 500 Goyal
1002 Etiquettes 400 Sumita
1003 Law 575 Rita
1004 IOT 200 Harish
1005 Python 280 Sumita

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.

import ___________________ as sql # Statement 1


mycon=sql.connect(host="localhost",user="root", password="root@123",
database="Bookshop")
cur=______________________ # Statement 2
Q=______________________ # Statement 3
cur.___________(Q) #Statement 4
mycon.commit()
mycon.close()
print("Book Details are Updated Successfully")

(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 by writing the query that Increase the Price of
the Books by 10% whose Price is more than 300.
(d)Complete the Statement 4 to execute the command that update the
records in the table Books.

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)

Q.2 Complete the following Database connectivity program by writing missing


statements and perform the given query.
TABLE: Books
BookI BName Price Author
d
1001 Netiquettes 500 Goyal
1002 Etiquettes 400 Sumita
1003 Law 575 Rita
1004 IOT 200 Harish
1005 Python 280 Sumita

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.

import ___________________ as sql # Statement 1


mycon=sql.connect(host="localhost",user="root", password="root@123",
database="Bookshop")
cur=______________________ # Statement 2
Q=______________________ # Statement 3
cur.___________(Q) #Statement 4
mycon.commit()
mycon.close()
print("Book Details are Updated Successfully")

(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 by writing the query that Increase the Price of
the Books by 10% whose Price is more than 300.
(d)Complete the Statement 4 to execute the command that update the
records in the table Books.
Q.1 Write a Menu Driven Program to perform the following:
(i) To read contents from a text file "ABC.TXT" that counts the number of
"the" or "then" words present in a text file.
(ii) To read the contents from text file "XYZ.TXT" and display the altered file
converted all the ‘a’s found in the file to ‘@’
Ex:
File Content: A
n apple a day keeps the doctor away
O/P: @pple @ d@y keeps the doctor @w@y.

Q.2 Complete the following Database connectivity program by writing missing


statements and perform the given query.
TABLE: TRAINER
Tid TName City DOJ
101 Allen Delhi 1998-10-15
102 Akash Mumbai 2002-12-24
103 Alex Chennai 2012-11-05
104 Akil Mumbai 2006-05-09
105 Meenakshi Madurai 2021-05-06

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.

import ___________________ as sql # Statement 1


mycon=sql.connect(host="localhost",user="root", password="trainer@123",
database="Company")
cur=______________________ # Statement 2
Query=______________________ # Statement 3
cur.execute(Query)
mycon.______________ #Statement 4
print("Trainer Details are Deleted Successfully")
mycon.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 by writing the query that deletes the trainer
details whose city is "Chennai".
(d)Complete the Statement 4 to - to add the record permanently in the database.

Q.1 Write a python program to create details of students(name, marks, rollno.) in a


csv file. Read and display the records of students who have scored less than 35
marks.

Q.2 Complete the following Database connectivity program by writing missing


statements and perform the given query.
TABLE: GRADUATE
Sid SName Stipend Dept
1 Arun 12000 Physics
2 Nisha 18000 CS
3 Mano 13000 Chemistry
4 Pooja 14500 Maths
5 Kumar 25000 CS

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.

import mysql.connector as sql


mycon=sql.connect(host="localhost",user="root", password="root",
database="University")
cur=______________________ # Statement 1
Query=______________________ # Statement 2
cur.____________(Query) # Statement 3
D=cur.fetchall()
print(D)
mycon.__________ #Statement 4

(a)Complete the Statement 1 to form the cursor object.


(b)Complete the Statement 2 to by writing the query that used to view the
details of the graduate whose Dept is "CS".
(c) Complete the Statement 3 to execute the Query.
(d)Complete the Statement 4 to close the connection

Q. 1 Write a menudriven Python program to implement PUSH(book_name,price), POP


and Display operations in Stack using List.

(Hint: Push the names of the book only if the price is greater than 300 otherwise ask
for the book details again.

Q.2 Complete the following Database connectivity program by writing missing


statements and perform the given query.

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

import mysql.connector as sql


mycon=_________________ # Statement 1
cur=______________________ # Statement 2
Q=______________________ # Statement 3
cur.____________(Q) # Statement 4
D=cur.fetchall()
print(D)
mycon.close()

Write a menu driven pyhon program to sort the given list using both Bubble Sort and
Insertion Sort.

Complete the following Database connectivity program by writing missing


statements and perform the given query.
TABLE: EMPLOYEE
Eid EName Salary Dept
1 Arun 12000 Sales
2 Nisha 18000 Purchase
3 Mano 13000 Finance
4 Pooja 14500 IT
5 Kumar 25000 Sales

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.

import mysql.connector as sql


mycon=sql.connect(host="localhost",user="root", password="root",
database="Tech")
cur=______________________ # Statement 1
Query=______________________ # Statement 2
cur.____________(Query) # Statement 3
D=cur.fetchall()
print(D)
mycon.__________ #Statement 4
(a)Complete the Statement 1 to form the cursor object.
(b)Complete the Statement 2 to by writing the query that used to view the
details of the Employees whose Dept is "Sales".
(c) Complete the Statement 3 to execute the Query.
(d)Complete the Statement 4 to close the connection

Write a program to perform all stack operations (PUSH, POP, DISPLAY).


Collect the details of players’ name and score.Push the details of the
players who have scored 100 or more. Otherwise ask the details of the
players again until the condition is met.

Complete the following Database connectivity program by writing missing


statements and perform the given query.
TABLE: Students
Roll Name Ag Percentag
e e
1 Arun 24 65
2 Ankit 21 71
3 Anu 20 80
4 Bala 19 67
5 Charan 18 95
6 Usha 23 82

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.

You might also like