0% found this document useful (0 votes)
81 views52 pages

CS Practical Record 24-25

Uploaded by

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

CS Practical Record 24-25

Uploaded by

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

SRI GURUKULAM SECONDARY SCHOOL, HOSUR

COMPUTER SCIENCE – PRACTICAL REPORT FILE

Programming in Python & MySQL


Subject Code : 083
Academic Year : 2024 - 2025

Name of the Student:


Class :
Register Number :
BONAFIDE CERTIFICATE

Certificate to be the bonafide record of Computer Science practical work


done by Master/Miss _________________________________________

Of class ________ of Sri Gurukulam Secondary School, during the academic


year 2024-2025.

Teacher In-charge

Submitted for SSCE – Practical held at Sri Gurukulam Secondary School

Name of the student : _____________________________

Register Number : _____________________________

Examination Centre & Code : _____________________________

Date of Examination : _________________________________

Internal Examiner Principal External Examiner


INDEX

Signature
Page
No. Date Title of the Program Of the
No.
Teacher
Finding the factorial value for
1 1
the given number.
Finding Fibonacci series of
2 2
given number.
Checking whether the given
3 3
string is palindrome or not.
Menu driven Program to calculate
4 4
area of different shapes.
Creating a program based on
5 random number generation between 6
1 to 6.
Displaying the sum of even
6 7
numbers in a list.
Creating a menu driven program
7 to perform arithmetic 8
operations.
Creating a program to read a
text file line by line and
8 10
display each word separated by
‘#’.
Copying all the lines from a
file that contain the character
9 11
‘a’ and write it to another
file.
Creating python program to
10 display short words from the 12
text file.
Creating python program to read
a text file and display the
11 number of Vowels /Consonants/ 13
Upper_case /Lower_case
Characters.
Creating and Searching record in
12 15
a binary file.
Creating and updating records in
13 18
a binary file.
Creating and Searching
14 employee’s records in a CSV 21
file.
Creating a Python program to
15 implement stack operations using 23
lists.
Creating a Python program to
16 implement stack operations 25
(Dictionary).
Creating, inserting values,
17 updating and display a table in 29
many forms using SQL Queries.
Creating table “Teacher” to
18 execute basic commands using 33
SQL.
Creating table “Student” to
19 execute basic commands using 35
SQL.
Creating table Company and
20 Customer and to execute basic 38
commands using SQL.
Creating table Doctor and Salary
21 and to execute basic commands 41
using SQL.
SQL Connectivity – I ( Creating
22 44
& Insertion).
SQL Connectivity – II
23 46
(Displaying data).
SQL Connectivity- III (Updating
24 47
& Delete).
DATE : PROGRAM NO : 1

Finding the factorial value for the given number

Aim:

To write a program to find factorial value for the given number.

Source Code:

Result:
Thus, the above program has been executed and the output is verified successfully.

Output :

1
DATE : PROGRAM NO : 2

Finding Fibonacci series of given number

Aim:
To write a program in Python to find Fibonacci series for given number.

Source Code:

Result:
Thus, the above program has been executed and the output is verified successfully.

Output:

2
DATE : PROGRAM NO : 3

Checking whether the given string is palindrome or not.

Aim:
To write a program in Python to find given string is palindrome or not.

Source code:

Result:
Thus, the above program has been executed and the output is verified successfully.

Output:

3
DATE : PROGRAM NO : 4
Menu driven Program to calculate area of different shapes.

Aim:
To write a menu driven program to calculate area of different shapes.

Source code:

4
Result:
Thus, the above program has been executed and the output is verified successfully.

Output:

5
DATE : PROGRAM NO : 5

Creating a program based on random number generation between 1 to 6

Aim:
To create a python program to generate random numbers from 1 to 6 using random module.

Source code:

Result:
Thus, the above program has been executed and the output is verified successfully.

Output:

6
DATE : PROGRAM NO : 6

Displaying the sum of even numbers in a list

Aim:
To write a Python program to display the sum of even numbers of a list .

Source Code:

Result:
Thus, the above program has been executed and the output is verified successfully.

Output:

7
DATE : PROGRAM NO : 7
Creating a menu driven program to perform arithmetic operations.

Aim:
To write a menu driven program to perform arithmetic operations.
Source Code:

8
Result:
Thus, the above program has been executed and the output is verified successfully.

Output:

9
DATE : PROGRAM NO : 8
Creating a program to read a text file line by line and display each word
separated by ‘#’

Aim:
To write a program to read a text file line by line and display each word separated by a #.

Source Code:

Result:

Thus, the above program has been executed and the output is verified successfully.

Text File:

Output:

10
DATE : PROGRAM NO : 9
Copying all the lines from a file that contain the character ‘a’ and write it
to another file.

Aim :
To write a program to copy all the lines from a file that contain the character `a' and
write it to another file

Source Code:

Result:

Thus, the above program has been executed and the output is verified successfully.

Text File – Story.txt

Output:

New.txt

11
DATE : PROGRAM NO : 10

Creating python program to display short words from the text file

Aim:
To write a method display() in python, to read the lines from “Story.txt” and display those
words which are less than 5 characters.
Source Code:

Result:
Thus, the above program has been executed and the output is verified successfully.

Text File – Story.txt

Output:

12
DATE : PROGRAM NO : 11

Creating python program to read a text file and display the number of
Vowels / Consonants / Upper_case / Lower_case Characters

Aim:
To write a python program to read a text file and display the number of Vowels,
Consonants, Upper_case, Lower_case Characters present.

Source Code:

Result:
Thus, the above program has been executed and the output is verified successfully.

13
Text File – Story.txt

Output:

14
DATE : PROGRAM NO : 12

Creating and Searching record in a binary file

Aim:
To write a program to Create a binary file with roll number, name and marks. Search for
a given roll number and display the details of the student, if not found display the appropriate
message.

Source Code:

15
Result:
Thus, the above program has been executed and the output is verified successfully.
Binary File : stud.bin

16
Output:

17
DATE : PROGRAM NO : 13

Creating and updating records in a binary file

Aim:
To write a program to Create a binary file with roll number, name and marks. Search for
a roll number and update the marks of the student, if not found display the appropriate message.

Source Code:

18
Result:
Thus, the above program has been executed and the output is verified successfully.

19
Output:

20
DATE : PROGRAM NO : 14

Creating and Searching employee’s records in a CSV file

Aim:
To write a program to create a CSV file to store Empno, Name, Salary and search any Empno and
display Name, Salary and if not found display appropriate message.
Source Code:

21
Result:
Thus, the above program has been executed and the output is verified successfully.

CSV File:

Output:

22
DATE : PROGRAM NO : 15
Creating a Python program to implement stack operations using lists.

Aim:
To Write a program to implement all basic operations of a stack, such as adding element
(PUSH operation), removing element (POP operation) and displaying the stack elements
(Traversal operation) using lists.

Source Code:

23
Result:
Thus, the above program has been executed and the output is verified successfully.
Output:

24
25
DATE : PROGRAM NO : 16
Creating a Python program to implement stack operations (Dictionary)

Aim:
To write a program with separate user-defined functions to perform the following operations.
(i) To create a function Push (stk, D), where stack is an empty list and D is Dictionary of items.
From the dictionary Push the keys (name of the student) into a stack, where the corresponding
value (marks) is greater than 70.
(ii) To create a Function Pop (stk), where stk is a stack implemented by a list of student names.
The function returns the items deleted from the stack.
(iii) To display the elements of the stack (after performing PUSH or POP)

Source Code:

26
Result:
Thus, the above program has been executed and the output is verified successfully.

27
Output:

28
DATE : PROGRAM NO : 17
Creating, inserting values, updating and display a table in many forms
using SQL Queries

Aim:
Creating, inserting values, updating and display a table in many forms using SQL Queries

Creating a table:

mysql> use mysql


Database changed

mysql> create table student(sid int(5), sname char(20), gender char(7), city char(30),
phonenumint(10));
Query OK, 0 rows affected (0.08 sec)

mysql> create table marks(sid int(5), Computer int, Physics int, Chemistry int, Biology int);
Query OK, 0 rows affected (0.08 sec)

Inserting values into table:

mysql> insert into student values(101,'Sathya','Male','Krishnagiri',2467453);


Query OK, 1 row affected (0.03 sec)

mysql> insert into student values (102,'Sindhu,'Female','Hosur',2467834),


(103,'Karthick','Male','Krishnagiri', 2389345), (104,'Anitha','Female','Salem', 2387865),
(105,'Vimal','Male','Dharmapuri', 2356895);
Query OK, 4 row affected (0.03 sec)
Records : 4 Duplicates : 0 Warnings : 0

mysql> insert into marks values (101,89,67,58,90), (102,78,98,65,45), (103,56,78,83,97),


(104,99,48,69,75), (105,87,82,79,60);
Query OK, 5 row affected (0.03 sec)
Records : 5 Duplicates : 0 Warnings : 0

29
Displaying a table:

mysql> select * from student;


sid sname gender city phonenum
101 Sathya Male Krishnagiri 2467453
102 Sindhu Female Hosur 2467834
103 Karthick Male Krishnagiri 2389345
104 Anitha Female Salem 2387865
105 Vimal Male Dharmapuri 2356895
5 rows in set (0.00 sec)

mysql> select * from marks;


sid Computer Physics Chemistry Biology
101 89 67 58 90
102 78 98 65 45
103 56 78 83 97
104 99 48 69 75
105 87 82 79 60
5 rows in set (0.00 sec)

Selecting Specific Rows using WHERE clause

mysql> select * from student where sid=103;


sid sname gender city phonenum
103 Karthick Male Krishnagiri 2389345
1 rows in set (0.03 sec)

Sorting Results - ORDER BY clause


mysql> select * from student order by sname desc;
sid sname gender city phonenum
105 Vimal Male Dharmapuri 2356895
102 Sindhu Female Hosur 2467834
101 Sathya Male Krishnagiri 2467453
103 Karthick Male Krishnagiri 2389345
104 Anitha Female Salem 2387865
5 rows in set (0.00 sec)

30
mysql> select * from student where gender='Male' order by sname;
sid sname gender city phonenum
103 Karthick Male Krishnagiri 2389345
101 Sathya Male Krishnagiri 2467453
105 Vimal Male Dharmapuri 2356895
3 rows in set (0.01 sec)

Aggregate Functions
mysql> select sum(Computer) from marks;
sum(Computer)
409
1 rows in set (0.03 sec)

mysql> select avg(Computer) from marks;


avg(Computer)
81.8000
1 rows in set (0.01 sec)

mysql> select count(*) from marks;


Count(*)
5
1 rows in set (0.02 sec)

mysql> select count(distinct city) from student;


count(distinct address)
4
1 rows in set (0.01 sec)

mysql> select min(Biology), max(Chemistry) from marks;


min(Biology) max(Chemistry)
45 83

1 rows in set (0.05 sec)

31
Update Command

mysql> update marks set Total = Computer + Physics + Chemistry + Biology, Average=Total/4;
Query OK, 5 row affected (0.06 sec)
Row matched : 5 Changed : 5 Warnings : 0
mysql> select * from marks;

sid Computer Physics Chemistry Biology Total Average


101 89 67 58 90 304 76
102 78 98 65 45 286 72
103 56 78 83 97 314 79
104 99 48 69 75 291 73
105 87 82 79 60 308 77
5 rows in set (0.00 sec)

Delete Command

mysql>Delete from marks where total<300;


mysql>Select * from marks;

Drop Command

mysql>Drop table marks:

32
DATE : PROGRAM NO : 18
Creating table “Teacher” to execute basic commands using SQL.

Aim:
To create table “Teacher” and execute the given commands using SQL.

TABLE: TEACHER

No Name Age Department DateofJoin Salary Sex


1 Jishnu 34 Computer 10/01/97 12000 M
2 Sharmila 31 History 24/03/98 20000 F
3 Santhosh 32 Maths 12/12/96 30000 M
4 Shanmathi 35 History 01/07/99 40000 F
5 Ragu 42 Maths 05/09/97 25000 M
6 Shiva 50 History 27/02/97 30000 M
7 Shakthi 44 Computer 25/02/97 21000 M
8 Shriya 33 Maths 31/07/97 20000 F

1. To show all information about the teacher of history department.


2. To list the names of female teacher who are in Maths department.
3. To list names of all teachers with their date of joining in ascending order.
4. To count the number of teachers with age>35.
5. To count the number of teachers department wise.

SQL Commands:

CREATING TABLE TEACHER:

CREATE TABLE TEACHER(No int(2), Name varchar(15), Age int(3) , Department


varchar(15), Dateofjoin varchar(15) , Salary int(7) , Sex char(1));

INSERTING VALUES INTO TEACHER TABLE:

INSERT INTO TEACHER VALUES(1,’Jishnu’,34,’Computer’,’10/01/97’,12000,’M’);

33
OUTPUT:
1. select * from teacher where Department=’History’;
No Name Age Department DateofJoin Salary Sex
2 Sharmila 31 History 24/03/98 20000 F

4 Shanmathi 35 History 01/07/99 40000 F

6 Shiva 50 History 27/02/97 30000 M

2. select Name from teacher where Department=’Maths’ and Sex=’F’;

Name
Shriya

3. select Name , Dateofjoin from teacher order by Dateofjoin;

Name Dateofjoin
Santhosh 12/12/96
Jishnu 10/01/97
Shakthi 25/02/97
Shiva 27/02/97
Shriya 31/07/97
Ragu 05/09/97
Sharmila 24/03/98
Shamathi 01/07/99

4. select count(*) from teacher where Age>35;

5. select Department , count(*) from teacher group by department;

Department Count(*)
Computer 2
History 3
Maths 3

RESULT:
Thus the given program executed successfully.
34
DATE : PROGRAM NO : 19
Creating table “Student” to execute basic commands using SQL.

AIM:
To create table “Student” and execute the given commands using SQL.

TABLE: STUDENT

No Name Stipend Stream AvgMark Grade Class


1 Karan 400.00 Science 78.5 B 12B
2 Divakar 450.00 Science 89.2 A 11C
3 Divya 300.00 Commerce 68.6 C 12A
4 Arun 350.00 Commerce 73.1 B 12C
5 Robert 500.00 Humanities 90.6 A 11A
6 Sabina 400.00 Humanities 75.4 B 12A
7 Rubina 350.00 Science 64.4 C 12B
8 Vikas 450.00 Commerce 88.5 A 11B
9 John 500.00 Science 92.0 A 12A
10 Mohan 300.00 Commerce 67.5 C 12C

1. Alter Table to add new column DOB Date in Student Table.


2. Alter Table to change No Column to Roll NO also data size change.
3. Select all the Science stream students from STUDENT.
4. List all students sorted by AvgMark in Descending order.
5. Show Mohan Stipend is Greater than 200 or not.

SQL Commands:

CREATING TABLE STUDENT:

CREATE TABLE STUDENT(No int(2), Name varchar(15), Stipend Decimal(10,2) , Stream varchar(15),
AvgMark Decimal(5,2), Grade Char(1) , Class Varchar(5));

INSERTING VALUES INTO STUDENT TABLE:

INSERT INTO STUDENT VALUES(1,’Karan’,400.00,’Science’,78.5,’B’,’12B’);

35
OUTPUT:

1. Alter Table student add (DOB Date);


Mysql>Select * from student;

No Name Stipend Stream AvgMark Grade Class DOB


1 Karan 400.00 Science 78.5 B 12B
2 Divakar 450.00 Science 89.2 A 11C
3 Divya 300.00 Commerce 68.6 C 12A
4 Arun 350.00 Commerce 73.1 B 12C
5 Robert 500.00 Humanities 90.6 A 11A
6 Sabina 400.00 Humanities 75.4 B 12A
7 Rubina 350.00 Science 64.4 C 12B
8 Vikas 450.00 Commerce 88.5 A 11B
9 John 500.00 Science 92.0 A 12A
10 Mohan 300.00 Commerce 67.5 C 12C

2. Alter Table student change No RollNo Int(10);


Mysql>Describe student;

Field Type Null Key Default Extra


RollNo Int(10) YES NULL
Name Varchar(15) YES NULL
Stipend Decimal(10,2) YES NULL
Stream Varchar(15) YES NULL
AvgMark Decimal(5,2) YES NULL
Grade Char(1) YES NULL
Class Varchar(5) YES NULL

36
3. Select * from student where stream like ‘Science’;

No Name Stipend Stream AvgMark Grade Class DOB

1 Karan 400.00 Science 78.5 B 12B

2 Divakar 450.00 Science 89.2 A 11C

7 Rubina 350.00 Science 64.4 C 12B

9 John 500.00 Science 92.0 A 12A

4. Select * from student order by AvgMark Desc;

No Name Stipend Stream AvgMark Grade Class DOB


9 John 500 Science 92 A 12A
5 Robert 500 Humanities 90.6 A 11A
2 Divakar 450 Science 89.2 A 11C
8 Vikas 450 Commerce 88.5 A 11B
1 Karan 400 Science 78.5 B 12B
6 Sabina 400 Humanities 75.4 B 12A
4 Arun 350 Commerce 73.1 B 12C
3 Divya 300 Commerce 68.6 C 12A
10 Mohan 300 Commerce 67.5 C 12C
7 Rubina 350 Science 64.4 C 12B

5. Select Name, Stipend from student where Name =’Mohan’ and Stipend > 200;

Name Stipend

Mohan 300.00

Result:
Thus the given program executed successfully.

37
DATE : PROGRAM NO : 20
Creating table Company and Customer and to execute basic commands
using SQL.

AIM:
To create two tables, company and customer and execute the given commands using SQL.

TABLE : COMPANY

CID NAME CITY PRODUCTNAME


111 SONY DELHI TV
222 NOKIA MUMBAI MOBILE
333 ONIDA DELHI TV
444 SONY MUMBAI MOBILE
555 BLACKBERRY MADRAS MOBILE
666 CELL DELHI LAPTOP

TABLE : CUSTOMER

CUSTID NAME PRICE QTY CID

101 ROHAN SHARMA 70000 20 222

102 DEEPAK KUMAR 50000 10 666


103 MOHAN KUMAR 30000 5 111

104 SAHIL BANSAL 35000 3 333

105 NEHA SONI 25000 7 444

106 SONAL AGGARWAL 30000 5 333

1. To display those customer name which are having price less than 30000.
2. To display the name of the companies in reverse alphabetical order.
3. To increase the price by 1000 for those customer whose name starts with ‘S’
4. To add one more column totalprice with decimal (10,2) to the table customer
5. To display the details of company where productname as mobile.

38
SQL Commands:
CREATING TABLE COMPANY:

CREATE TABLE COMPANY(cid int(3) , name varchar(15) , city varchar(10), productname


varchar(15));

INSERTING VALUES INTO TABLE COMPANY:

INSERT INTO COMPANY VALUES (111, ‘SONY’, ‘DELHI’, ‘TV’), (222, ‘NOKIA’,
‘MUMBAI’, ‘MOBILE’), (333, ‘ONIDA’, ‘DELHI’, ‘TV’), (444, ‘SONY’, ‘MUMBAI’, ‘MOBILE’),
(555, ‘BLACKBERRY’, ‘MADRAS’, ‘MOBILE’), (666, ‘CELL’, ‘DELHI’, ‘LAPTOP’);
CREATING TABLE CUSTOMER:

CREATE TABLE CUSTOMER (custid int(3), name varchar(15), price int(10), qty int(3) ,
cid int(3));

INSERTING VALUES INTO TABLE CUSTOMER:

INSERT INTO CUSTOMER VALUES (101, ‘ROHAN SHARMA’, 70000, 20, 222), (102,
‘DEEPAK KUMAR’, 50000, 10, 666), (103, ‘MOHAN KUMAR’, 30000, 5, 111), (104, ‘SAHIL
BANSAL’, 35000, 3, 333), (104, ‘NEHA SONI’, 25000, 7, 444), (106, ‘SONAL AGGARWAL’,
20000, 5, 333);

OUTPUT :

1. select name from customer where price < 30000;

NAME

NEHA SONI

2. select name from company order by name desc;

NAME
SONY
ONIDA
NOKIA
DELL
BLACKBERRY

39
3. update customer set price = price + 1000 where name like ‘s%’;
select * from customer;

CUSTID NAME PRICE QTY CID


101 ROHAN SHARMA 70000 20 222

102 DEEPAK KUMAR 50000 10 666


103 MOHAN KUMAR 30000 5 111

104 SAHIL BANSAL 36000 3 333

105 NEHA SONI 25000 7 444

106 SONAL AGGARWAL 21000 5 333

4. alter table customer add totalprice decimal(10,2);


Select * from customer;

CUSTID NAME PRICE QTY CID TOTALPRICE

101 ROHAN SHARMA 70000 20 222 NULL


102 DEEPAK KUMAR 50000 10 666 NULL
103 MOHAN KUMAR 30000 5 111 NULL
104 SAHIL BANSAL 36000 3 333 NULL
105 NEHA SONI 25000 7 444 NULL
106 SONAL AGGARWAL 21000 5 333 NULL

5. select * from company where productname=’mobile’;

CID NAME CITY PRODUCTNAME

222 NOKIA MUMBAI MOBILE

444 SONY MUMBAI MOBILE

555 BLACKBERRY MADRAS MOBILE

RESULT:
Thus the given program executed successfully.
40
DATE : PROGRAM NO : 21

Creating table Doctor and Salary and to execute basic commands using SQL

AIM:
To create two tables for doctor and salary and execute the given commands using SQL.

TABLE:DOCTOR

TABLE: SALARY

1. Display NAME of all doctors who are in “MEDICINE” department having more than 10 years of
experience from table DOCTOR.
2. Display the average salary of all doctors working in “ENT” department using the tables
DOCTOR and SALARY. (Salary=BASIC+ALLOWANCE)
3. Display minimum ALLOWANCE of female doctors.
4. Display DOCTOR.ID , NAME from the table DOCTOR and BASIC , ALLOWANCE from
the table SALARY with their corresponding matching ID.
5. To display distinct department from the table doctor.

41
SQL Commands:

CREATING TABLE DOCTOR:

CREATE TABLE DOCTOR(ID int NOT NULL PRIMARY KEY, NAME char(25) , DEPT char(25) ,
SEX char , EXPERIENCE int);

INSERTING VALUES INTO TABLE DOCTOR:

INSERT INTO DOCTOR VALUES(101,”John”, “ENT”,’M’,12), (104,”Smith”,


“ORTHOPEDIC”,’M’,5), (107,”George”, “CARDIOLOGY”,’M’,10), (114,”Lara”, “SKIN”,’F’,3),
(109,”K George”, “MEDICINE”,’F’,9), (105,”Johnson”, “ORTHOPEDIC”,’M’,10), (117,”Lucy”,
“ENT”,’F’,3), (111,”Bill”, “MEDICINE”,’F’,12), (130,”Morphy”, “ORTHOPEDIC”,’M’,15);

CREATING TABLE SALARY:

CREATE TABLE SALARY(ID int, BASIC int, ALLOWANCE int, CONSULTATION int);

INSERTING VALUES INTO TABLE SALARY:

INSERT INTO SALARY VALUES (101, 12000,1000,300), (104, 23000,2300,500), (107, 32000,
4000, 500), (114, 12000, 5200, 100), (109,42000, 1700,200), (105, 18900, 1690, 300), (130, 21700,
2600, 300)

OUTPUT:

1. select NAME from DOCTOR where DEPT=”MEDICINE” and


EXPERIENCE >10;

42
2. select avg(BASIC+ALLOWANCE) as “avg salary” from DOCTOR , SALARY
where DOCTOR.ID=SALARY.ID and DEPT=”ENT”;

3. select min(ALLOWANCE) from SALARY, DOCTOR where


DOCTOR.SEX=’F’ and DOCTOR.ID=SALARY.ID;

4. select DOCTOR.ID, NAME, BASIC ,ALLOWANCE from DOCTOR,SALARY


where DOCTOR.ID=SALARY.ID;

5. select distinct(DEPT) from DOCTOR;

RESULT:

Thus the given program executed successfully.


43
DATE : PROGRAM NO : 22
SQL Connecting – I ( Creating & Insertion)

Aim:
To create a program to integrate MYSQL with python to create table to store the details of
employees.

Source Code:
import mysql.connector as mysql

db1 = mysql.connect(host="localhost",user="root",passwd="Student@123",database
="dharshini316" )

cursor = db1.cursor()
sql = "CREATE TABLE EMPS(empno integer primary key,ename varchar(25) not null,salary
float);"
cursor.execute(sql)
print(“Table created successfully”)

sql = "INSERT INTO EMPS VALUES(1,'Anil PS',86000),(2,'Anil


PS',86500),(3,'Vicky',90000),(4,'Ram',99000),(5,'Karthick',92000)" ;
try:
cursor.execute(sql)
db1.commit()
except:
db1.rollback()

db1.close()

44
Output:

45
DATE : PROGRAM NO : 23
SQL Connectivity – II (Displaying data)

Aim:
To create a program to integrate MYSQL with python to display the details of the employees.

Source Code:
import mysql.connector as mysql
db1= mysql.connect(host="localhost",user="root",passwd='Student@123',database='record')
cursor= db1.cursor()
cursor.execute("select * from EMPCHECK1")
print("Data of table EMPCHECK1 displayed")
for i in cursor.fetchmany(3):
print(i)
print("\nTotal records: ",cursor.rowcount)

Output:

46
DATE : PROGRAM NO : 24
SQL Connectivity- III (Updating & Delete)

Aim:
To create a program to integrate MYSQL with python to update and delete the records in the
table.

Source Code:
import mysql.connector as mysql
db1= mysql.connect(host="localhost",user="root",passwd='Student@123',
database='dharshini316')
cursor= db1.cursor()
#update_cmd = "update EMPCHECK1 set salary = 200000 where ename = 'Ram'"
#print("Values updated successfully in the table")
delete_cmd = "delete from EMPCHECK1 where salary=86000"
print("Values deleted successfully in the table")
#cursor.execute(update_cmd)
#db1.commit()
cursor.execute(delete_cmd)
db1.commit()

Output:

47

You might also like