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

Practical Record 2023-24

Practical note

Uploaded by

yogeshpratheep97
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)
25 views57 pages

Practical Record 2023-24

Practical note

Uploaded by

yogeshpratheep97
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/ 57

Page

S.No. Date Name of the Programme Sign


No.
Write a menu driven python program to perform arithmetic
1.
operations

2. Write a python program to display FIBONACCI series

Write a python program to display the sum of even numbers


3.
of a list
Write a python program to find factorial of a number using
4.
function
Write a menu driven python program to find area of circle,
5.
rectangle and triangle
Write a python program to implement mathematical
6.
functions

Write a python program to read a text file line by line and


7.
display each word separated by '#'

Write a python program to read a text file and display the


8. number of vowels/consonants/lower case/ upper case
characters

Write a python program to create and search records in


9.
binary file

Write a python program to create and update records in


10.
binary file

Creating a python program to copy particular lines of a text


11.
file that contain the character ‘a’ into an another text file

Creating a python program to generate random number


12.
between 1 to 6
Write a Python program to implement a stack using list
13.
(PUSH & POP Operation on Stack).
Write a python program to create a CSV file by entering
14. user-id and password, read and search the password for given
user- id.
Write a query to Create a student table, insert record and
15.
view records
Write a query using ALTER table command to add new
16. attributes / modify data type / drop attribute and Write a
query using UPDATE command to modify data
Write a query using ORDER By command to display data in
17. ascending / descending order and Write a query using
DELETE command to remove tuple(s)
Write a query using GROUP BY command and also to
18. perform aggregate functions min, max, sum, count and
average

19. Write a query to Join of two tables

Write a python program to integrate python and mysql for


20.
creating Table
Write a python program to integrate python and mysql for
21.
inserting records
Write a python program to integrate python and mysql for
22.
display records
Write a python program to integrate python and mysql for
23.
delete records
Write a python program to integrate python and mysql for
24.
update records
Write a python program to integrate python and mysql to add
25.
a new column and remove a column
EX.NO: 1
DATE:

CREATING A MENU DRIVEN PROGRAM TO PERFORM ARITHMETIC


OPERATIONS

AIM:

To write a menu driven Python Program to perform Arithmetic operations (+,-*, /)based
on the user’s choice.

SOURCE CODE:

RESULT:
Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Program Executed Output:


Run – 1:

RUN- 2

***************************************************************************************
EX.NO: 2
DATE:

CREATING A PYTHON PROGRAM TO DISPLAY FIBONACCI SERIES

AIM:
To write a Python Program to display Fibonacci Series up to ‘n’ numbers.

SOURCE CODE:

RESULT:
Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program Output:

RUN -1:

RUN -2 :

*****************************************************************************************
EX.NO: 5
DATE:

CREATING A PYTHON PROGRAM TO DISPLAY THE SUM OF EVEN NUMBERS


OF A LIST

AIM:

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

SOURCE CODE:

RESULT:
Thus, the above Python program is executed successfully and the output is verified.

SAMPLE OUTPUT:

**************************************************************************************
EX.NO: 6

DATE:

CREATING A PYTHON PROGRAM TO FIND FACTORIAL OF A NUMBER


USING FUNCTION

AIM:
To write a Python program to find a Factorial of a number inputted by the user.

SOURCE CODE:

RESULT:

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

SAMPLE OUTPUT:

RUN – 1:

RUN – 2:

**************************************************************************************
EX.NO: 7

DATE:

CREATING A MENU DRIVEN PROGRAM TO FIND AREA OF CIRCLE, RECTANGLE AND


TRIANGLE

AIM:
To write a menu driven Python Program to find Area of Circle, Rectangle and Triangle.
Using function.

SOURCE CODE:

RESULT:
Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

RUN – 1:

RUN – 2:

**************************************************************************************
EX.NO: 8

DATE:

CREATING A PYTHON PROGRAM TO IMPLEMENT MATHEMATICAL FUNCTIONS

AIM:
To write a Python program to implement python mathematical functions to find:
(i) To find Square of a Number.
(ii) To find Log of a Number(i.e. Log10)
(iii) To find Quad of a Number

SOURCE CODE:

RESULT:
Thus, the above Python program is executed successfully and the output is verified.

SAMPLE OUTPUT:

Python Executed Program Output:

**************************************************************************************
EX.NO: 11

DATE:

CREATING A PYTHON PROGRAM TO READ A TEXT FILE LINE BY LINE AND


DISPLAY EACH WORD SEPARATED BY '#'

AIM:

To write a Python Program to Read a text file "Story.txt" line by line and displayeach
word separated by '#'.

SOURCE CODE:

Result:

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

SAMPLE OUTPUT:

Story.txt:

***************************************************************************
EX.NO: 9
DATE:

CREATING A PYTHON PROGRAM TO READ A TEXT FILE AND DISPLAY THE


NUMBER OF VOWELS/CONSONANTS/LOWER CASE/ UPPER CASE CHARACTERS.

AIM:

To write a Python Program to read a text file "Story.txt" and displays the number of
Vowels/ Consonants/ Lowercase / Uppercase/characters in the file.

SOURCE CODE:

RESULT:
Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:
Story.txt:

*******************************************************************************
EX.NO: 14
DATE:

CREATING A PYTHON PROGRAM TO CREATE AND SEARCH RECORDS IN


BINARY FILE

AIM:

To write a Python Program to Create a binary file with roll number and name.
Search for a given roll number and display the name, if not found display
appropriate message.

SOURCE CODE:

Result:
Thus , the above Python program is executed successfully and the output is verified.
SAMPLE OUPUT:

PYTHON PROGRAM EXECUTED OUTPUT:

************************************************************************************
EX.NO: 16
DATE:

CREATING A PYTHON PROGRAM TO CREATE AND UPDATE RECORDS IN


BINARY FILE

AIM:
To write a Python Program to Create a binary file with roll number and name. Update the
mark for a given roll number and display the records, if not found display appropriate
message.

SOURCE CODE:

Result:
Thus , the above Python program is executed successfully and the output is verified.
SAMPLE OUPUT:

PYTHON PROGRAM EXECUTED OUTPUT:


EX.NO:12

DATE:

CREATING A PYTHON PROGRAM TO COPY PARTICULAR LINES OF A TEXT FILE


INTO AN ANOTHER TEXT FILE

AIM:

To write a python program to read lines from a text file "Sample.txt" and copy those lines
into another file which are starting with an alphabet 'a' or 'A'.

SOURCE CODE:

Result:
Thus the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:

Python Executed Program output:


Sample.txt:

Python Executed Program Output:

New.txt:

*****************************************************************************************
EX.NO: 3
DATE:

CREATING A PYTHON PROGRAM TO GENERATE RANDOM NUMBER


BETWEEN 1 TO 6

AIM:

To write a Python program to generate random number between 1 to 6 to simulate


the dice.

SOURCE CODE:

RESULT:
Thus, the above Python program is executed successfully and the output is verified.

SAMPLE OUTPUT:
Python Executed Output Program:

**************************************************************************************
Ex.No.13 Write a Python program to implement a stack using list (PUSH & POP
Operation on Stack).

AIM:
To Write a Python program to implement a stack using list (PUSH & POP
Operation on Stack).

PROGRAM:

defisEmpty(s):
if s==[]:
return True
else:
return False

def push(s,item):
s.append(item)
print("Element inserted....")
print(s)

def Pop(s):
if isEmpty(s):
print('Stack is Empty...')
else:
print('Deleted Element ...',s.pop())

def peek(s):
if isEmpty(s):
print('Stack is Empty...')
else:
print('Element at Top of the stack:',s[-1])

def show(s):
if isEmpty(s):
print('Stack is empty ... Underflow Case')
else:
for i in range(len(s)-1,-1,-1):
print(s[i])
s=[]
while True:
print('****** STACK IMPLEMENTATION USING LIST ******')
print('1: PUSH')
print('2: POP')
print('3: PEEK')
print('4: Show')
print('5: Exit')
ch=int(input('Enter choice:'))
if ch==1:
val=int(input('Enter no. to push:'))
push(s,val)
elif ch==2:
Pop(s)
elif ch==3:
peek(s)
elif ch==4:
show(s)
else:
print('Exit...')
break
INPUT & OUTPUT:

****** STACK IMPLEMENTATION USING LIST ******


1: PUSH
2: POP
3: PEEK
4: Show
5: Exit
Enter choice:1
Enter no. to push:10
Element inserted....
[10]
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: POP
3: PEEK
4: Show
5: Exit
Enter choice:1
Enter no. to push:20
Element inserted....
[10, 20]
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: POP
3: PEEK
4: Show
5: Exit
Enter choice:1
Enter no. to push:30
Element inserted....
[10, 20, 30]
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: POP
3: PEEK
4: Show
5: Exit
Enter choice:2
Deleted Element ... 30
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: POP
3: PEEK
4: Show
5: Exit
Enter choice:3
Element at Top of the stack: 20
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: POP
3: PEEK
4: Show
5: Exit
Enter choice:4
20
10
****** STACK IMPLEMENTATION USING LIST ******
1: PUSH
2: POP
3: PEEK
4: Show
5: Exit
Enter choice:5
Exit...
>>>

RESULT:
Thus, the above Python program is executed successfully and the output is verified
Ex.No.14 Write a python program to create a CSV file by entering user-id and
password, read and search the password for given user- id.

AIM:
To write Python Program to create a CSV file by entering user-id and
password, read and search the password for given user- id.

PROGRAM:

import csv
with open("user_info.csv", "w") as obj:
fileobj = csv.writer(obj)
fileobj.writerow(["User Id", "password"])
while(True):
user_id = input("enter id: ")
password = input("enter password: ")
record = [user_id, password]
fileobj.writerow(record)
x = input("press Y/y to continue and N/n to terminate the program\n")
if x in "Nn":
break
elif x in "Yy":
continue
with open("user_info.csv", "r") as obj2:
fileobj2 = csv.reader(obj2)
given = input("enter the user id to be searched\n")
for i in fileobj2:
next(fileobj2)
# print(i,given)
if i[0] == given:
print(i[1])
break
INPUT & OUTPUT:
enter id: 101
enter password: 123
press Y/y to continue and N/n to terminate the program
y
enter id: 102
enter password: 456
press Y/y to continue and N/n to terminate the program
n
enter the user id to be searched
102
456

RESULT:
Thus, the above Python program is executed successfully and the output is verified
Ex.No.15 Write a query to create a student table, insert records and view records

AIM:
To write a query to Create a student table, insert record and view records

QUERY:
1. To display all databases in MySql
2. To Create database “school”
3. To view databases in MySql
4. To select or open a database “school”
5. To create the structure of the Table “student”
6. To view the structure of the Table “student”
7. To insert records into the Table “student”
8. To View Records of the Table “student”
9. To display rollno, studentname with roll no 4
10. To display the student records whose fees greater than 3000
11. To display the student records whose fees greater than 2500 and lesser than 3500
12. To display the student records whose studentname starts with letter ‘S’
INPUT & OUTPUT:

To display all databases in MySql


mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+

To Create database “school”


mysql> create database school;

To view databases in MySql


mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school |
|sys |
+--------------------+

To select or open a database “school”


mysql> use school;
Database changed

To create the structure of the Table “student”


mysql> CREATE TABLE STUDENT
-> (ROLLNO INT PRIMARY KEY,
-> STUDENTNAME VARCHAR(20) NOT NULL,
-> SEX VARCHAR(5) NOT NULL,
-> DOB DATE NOT NULL,
-> FEES FLOAT(10,2) NOT NULL);

To view the structure of the Table “student”


mysql> DESCRIBE STUDENT;
To insert records into the Table “student”
mysql> INSERT INTO STUDENT
->VALUES(1,'KUMAR','M','2007-03-24',2400);

mysql> INSERT INTO STUDENT


->VALUES(2,'SIVA','M','2006-09-17',3200);

mysql> INSERT INTO STUDENT


->VALUES(3,'GOKUL','M','2006-12-29',2700);

mysql> INSERT INTO STUDENT


->VALUES(4,'SITA','F','2007-02-03',2300);

mysql> INSERT INTO STUDENT


->VALUES(5,'SUGARTHI','F','2006-10-21',3600);

To View Records of the Table “student”


mysql> SELECT * FROM STUDENT;

To display rollno, studentname with roll no 4


mysql> SELECT ROLLNO,STUDENTNAME
-> FROM STUDENT
-> WHERE ROLLNO=4;

To display the student records whose fees greater than 3000


mysql> SELECT *
-> FROM STUDENT
-> WHERE FEES>3000;
To display the student records whose fees greater than 2500 and lesser than 3500
mysql> SELECT *
-> FROM STUDENT
-> WHERE FEES>2500 AND FEES<3500;

To display the student records whose studentname starts with letter ‘S’
mysql> SELECT *
-> FROM STUDENT
-> WHERE STUDENTNAME LIKE 'S%';

RESULT:

Thus, the above MYSQL Query is executed successfully and the output is verified
Ex.No.16 Write a query using ALTER table command to add new attributes /
modify data type / drop attribute and Write a query using UPDATE
command table to modify data
AIM:
To write a query using ALTER table command to add new attributes, modify data
type and drop attribute and to write a query using UPDATE command to modify data

QUERY:
1. To view the structure of the Table “student”
2. To add new column name PHYSICS, MATHS, TOTAL_MARKS and REMARKS in
the existing Table “student”
3. To modify the size of the column “studentname” in the existing Table “student”
4. To view the structure of the Table “student”
5. To delete or remove column name “remarks” in the existing Table “student”
6. To view the structure of the Table “student”
7. To display the student records
8. To update PHYSICS and MATHS subject marks of students in the Table “student”
9. To display the student records
10. To update and calculate TOTAL_MARKS by adding marks of 2 subjects in the Table
“student”
11. To display the student records
INPUT & OUTPUT:

To view the structure of the Table “student”


mysql> DESCRIBE STUDENT;

To add new column name PHYSICS, MATHS, TOTAL_MARKS and REMARKS in


the existing Table “student”
mysql> ALTER TABLE STUDENT
-> ADD (PHYSICS INT,MATHS INT,TOTAL_MARKS INT,REMARKS
VARCHAR(20));

To modify the size of the column “studentname” in the existing Table “student”
mysql> ALTER TABLE STUDENT
-> MODIFY STUDENTNAME VARCHAR(25);

To view the structure of the Table “student”


mysql> DESCRIBE STUDENT;

To delete or remove column name “remarks” in the existing Table “student”


mysql> ALTER TABLE STUDENT
-> DROP REMARKS;
To view the structure of the Table “student”
mysql> DESCRIBE STUDENT;
To display the student records
mysql> SELECT * FROM STUDENT;

To update PHYSICS and MATHS subject marks of students in the Table “student”
mysql> UPDATE STUDENT
-> SET PHYSICS=67,MATHS=78
-> WHERE ROLLNO=1;

mysql> UPDATE STUDENT


-> SET PHYSICS=65,MATHS=85
-> WHERE ROLLNO=2;

mysql> UPDATE STUDENT


-> SET PHYSICS=76,MATHS=95
-> WHERE ROLLNO=3;

mysql> UPDATE STUDENT


-> SET PHYSICS=63,MATHS=79
-> WHERE ROLLNO=4;

mysql> UPDATE STUDENT


-> SET PHYSICS=89,MATHS=98
-> WHERE ROLLNO=5;

To display the student records


mysql> SELECT * FROM STUDENT;
To update and calculate TOTAL_MARKS by adding marks of 2 subjects in the Table
“student”

mysql> UPDATE STUDENT


-> SET TOTAL_MARKS=PHYSICS+MATHS;

To display the student records


mysql> SELECT * FROM STUDENT;

RESULT:

Thus, the above MYSQL Query is executed successfully and the output is verified
Ex.No. 17 Write a query using ORDER BYClause to display data in ascending /
descending order and Write a query using DELETE command to remove
tuple(s)

AIM:

To write a query using ORDER By command to display data in ascending /


descending order and to write a query using DELETE command to remove tuple(s)

QUERY:
1. To display the student records
2. To display the student records in ascending order based on student name
3. To display the student records in descending order based on TOTAL_MARKS
4. To delete the student record whose roll no. is 2
5. To display the student records
6. To delete the student record whose studentname is GOKUL
7. To display the student records
INPUT & OUTPUT:

To display the student records


mysql> SELECT * FROM STUDENT;

To display the student records in ascending order based on student name


mysql> SELECT *
-> FROM STUDENT
-> ORDER BY STUDENTNAME;

To display the student records in descending order based on TOTAL_MARKS


mysql> SELECT ROLLNO,STUDENTNAME,PHYSICS,MATHS,TOTAL_MARKS
-> FROM STUDENT
-> ORDER BY TOTAL_MARKS DESC;

To delete the student record whose roll no.is 2


mysql> DELETE FROM STUDENT
-> WHERE ROLLNO=2;

To display the student records


mysql> SELECT ROLLNO,STUDENTNAME
-> FROM STUDENT;
To delete the student record whose studentname is GOKUL
mysql> DELETE FROM STUDENT
-> WHERE STUDENTNAME='GOKUL';

To display the student records


mysql> SELECT ROLLNO,STUDENTNAME
-> FROM STUDENT;

RESULT:

Thus, the above MYSQL Query is executed successfully and the output is verified
Ex.No.18 Write a query using GROUP BY command and also to perform aggregate
functions min, max, sum, count and average

AIM:
To write a query using GROUP BY command and also to perform aggregate
functions min, max, sum, count and average

QUERY:
1. To display the student records
2. To count the number of students in each stream
3. To find total marks of students in each stream
4. To find total marks of students in each stream whose total marks greater than 150
5. To find average marks of students in each stream
6. To find minimum marks of students in each stream
7. To find maximum marks of students in each stream
INPUT & OUTPUT:

To display the student records


mysql> SELECT * FROM STUDENT;

To count the number of students in each stream


mysql> SELECT STREAM,COUNT(*)
-> FROM STUDENT
-> GROUP BY STREAM;

To find total marks of students in each stream


mysql> SELECT STREAM,SUM(MARK)
-> FROM STUDENT
-> GROUP BY STREAM;
To find total marks of students in each stream whose total marks greater than 150
mysql> SELECT STREAM,SUM(MARK)
-> FROM STUDENT
-> GROUP BY STREAM
-> HAVING SUM(MARK)>150;

To find average marks of students in each stream


mysql> SELECT STREAM,AVG(MARK)
-> FROM STUDENT
-> GROUP BY STREAM;

To find minimum marks of students in each stream


mysql> SELECT STREAM,MIN(MARK)
-> FROM STUDENT
-> GROUP BY STREAM;
To find maximum marks of students in each stream
mysql> SELECT STREAM,MAX(MARK)
-> FROM STUDENT
-> GROUP BY STREAM;

RESULT:

Thus, the above MYSQL Query is executed successfully and the output is verified
Ex.No.19 Write a query to Join of two tables

AIM:
To write a query to join of two tables

QUERY:
1. To display the records from student
2. To display the records from stream
3. To Join two Tables “student” and “stream” using Equi Join
4. To Join two Tables “student” and “stream” using Natural Join
INPUT & OUTPUT:

To display the records from student


mysql> SELECT * FROM STUDENT;

To display the records from stream


mysql> SELECT * FROM STREAM;

To Join two Tables “student” and “stream” using Equi Join


mysql> SELECT *
-> FROM STUDENT,STREAM
-> WHERE STUDENT.SNO=STREAM.SNO;

mysql> SELECT RNO,NAME,MARK,STREAMNAME


-> FROM STUDENT,STREAM
-> WHERE STUDENT.SNO=STREAM.SNO;

To Join two Tables “student” and “stream” using Natural Join


mysql> SELECT RNO,NAME,MARK,STREAMNAME
-> FROM STUDENT
-> NATURAL JOIN STREAM;

RESULT:

Thus, the above MYSQL Query is executed successfully and the output is verified
Ex.No.20 Write a python program to integrate python and mysql for creating
Table

AIM:
To write a python program to integrate python and mysql for creating
Table

PROGRAM:
importmysql.connector as c
con=c.connect(host='localhost',database='school',user='root',passwd='vvis')

def create():
crq=con.cursor()
crq.execute("create table class12(rnoint primary key,namevarchar(20),dob date, marks
int,streamvarchar(20))")
con.commit()
print("Table Created....!")
con.close()

create()
.
INPUT & OUTPUT:

Table Created....!

mysql> show tables;

mysql>desc class12;

RESULT:

Thus, the above Python program is executed successfully and the output is verified
Ex.No.21 Write a python program to integrate python and mysql for inserting
records

AIM:
To write a python program to integrate python and mysql for inserting
records

PROGRAM:
importmysql.connector as c
con=c.connect(host='localhost',database='school',user='root',passwd='vvis')

def insert():
crq=con.cursor()
crq.execute("insert into class12(rno,name,dob,marks,stream) values('101','Arun', '2005-12-
23',78,'biocs')")
con.commit()
print("Values Inserted....!")
con.close()

insert()
INPUT & OUTPUT:

Values Inserted....!

mysql> select * from class12;

RESULT:
Thus, the above Python program is executed successfully and the output is verified
Ex.No.22 Write a python program to integrate python and mysql for display
records

AIM:
To write a python program to integrate python and mysql for display records

PROGRAM:
importmysql.connector as c
con=c.connect(host='localhost',database='school',user='root',passwd='vvis')

def display():
crq=con.cursor()
crq.execute("Select* from class12")
for k in crq:
print(k)
print()
con.commit()
print("Records Are...!")
con.close()

display()
INPUT & OUTPUT:

(101, 'Arun', datetime.date(2005, 12, 23), 78, 'biocs')


(102, 'raja', datetime.date(2005, 12, 21), 79, 'biocs')
(103, 'arul', datetime.date(2005, 11, 21), 67, 'biocs')
(104, 'anand', datetime.date(2005, 9, 19), 65, 'biocs')
(105, 'ravi', datetime.date(2005, 8, 20), 86, 'biocs')

Records Are...!

RESULT:
Thus, the above Python program is executed successfully and the output is verified
Ex.No.23 Write a python program to integrate python and mysql for delete
records

AIM:
To write a python program to integrate python and mysql for delete records

PROGRAM:
importmysql.connector as c
con=c.connect(host='localhost',database='school',user='root',passwd='vvis')

def delete():
crq=con.cursor()
roll=int(input("Enter roll number of the student to be deleted : "))
rl=(roll,)
sql="Delete from class12 where rno=%s"
crq.execute(sql,rl)
con.commit()
print("Deleted")
con.close()

delete()
INPUT & OUTPUT:
mysql> select * from class12;
+-----+-------+------------+-------+--------+
| rno | name | dob | marks | stream |
+-----+-------+------------+-------+--------+
| 101 | Arun | 2005-12-23 | 78 | biocs |
| 102 | raja | 2005-12-21 | 79 | biocs |
| 103 | arul | 2005-11-21 | 67 | biocs |
| 104 | anand | 2005-09-19 | 65 | biocs |
| 105 | ravi | 2005-08-20 | 86 | biocs |
+-----+-------+------------+-------+--------+
5 rows in set (0.00 sec)

Enter roll number of the student to be deleted: 105


Deleted

mysql> select * from class12;


+-----+-------+------------+-------+--------+
| rno | name | dob | marks | stream |
+-----+-------+------------+-------+--------+
| 101 | Arun | 2005-12-23 | 78 | biocs |
| 102 | raja | 2005-12-21 | 79 | biocs |
| 103 | arul | 2005-11-21 | 67 | biocs |
| 104 | anand | 2005-09-19 | 65 | biocs |
+-----+-------+------------+-------+--------+
4 rows in set (0.00 sec)

RESULT:
Thus, the above Python program is executed successfully and the output is verified
Ex.No.24 Write a python program to integrate python and mysql for update
records

AIM:
To write a python program to integrate python and mysql for update records

PROGRAM:
importmysql.connector as c
con=c.connect(host='localhost',database='school',user='root',passwd='vvis')

def update():
crq=con.cursor()
crq.execute("update class12 set marks=98 where rno=101")
con.commit()
print("Marks Updated")
con.close()

update()
INPUT & OUTPUT:
mysql> select * from class12;
+-----+-------+------------+-------+--------+
| rno | name | dob | marks | stream |
+-----+-------+------------+-------+--------+
| 101 | Arun | 2005-12-23 | 78 | biocs |
| 102 | raja | 2005-12-21 | 79 | biocs |
| 103 | arul | 2005-11-21 | 67 | biocs |
| 104 | anand | 2005-09-19 | 65 | biocs |
+-----+-------+------------+-------+--------+

Marks Updated

mysql> select * from class12;


+-----+-------+------------+-------+--------+
| rno | name | dob | marks | stream |
+-----+-------+------------+-------+--------+
| 101 | Arun | 2005-12-23 | 98 | biocs |
| 102 | raja | 2005-12-21 | 79 | biocs |
| 103 | arul | 2005-11-21 | 67 | biocs |
| 104 | anand | 2005-09-19 | 65 | biocs |
+-----+-------+------------+-------+--------+
4 rows in set (0.00 sec)

RESULT:
Thus, the above Python program is executed successfully and the output is verified
Ex.No.25 Write a python program to integrate python and mysql to add a new
column and remove a column

AIM:
To write a python program to integrate python and mysql to add a new column and
remove a column

PROGRAM:

importmysql.connector as c
con=c.connect(host='localhost',database='school',user='root',passwd='vvis')
defaddcolumn():
crq=con.cursor()
crq.execute("Alter table Class12 add remarks varchar(30) default 'VVIS'")
con.commit()
print("Column Added")
con.close()

addcolumn()

importmysql.connector as c
con=c.connect(host='localhost',database='school',user='root',passwd='vvis')

defremcolumn():
crq=con.cursor()
crq.execute(" Alter table Class12 drop remarks")
con.commit()
print("Column Removed")
con.close()

remcolumn()
INPUT & OUTPUT:

Column Added

mysql> select * from class12;


+-----+-------+------------+-------+--------+---------+
| rno | name | dob | marks | stream | remarks |
+-----+-------+------------+-------+--------+---------+
| 101 | Arun | 2005-12-23 | 98 | biocs | VVIS |
| 102 | raja | 2005-12-21 | 79 | biocs | VVIS |
| 103 | arul | 2005-11-21 | 67 | biocs | VVIS |
| 104 | anand | 2005-09-19 | 65 | biocs | VVIS |
+-----+-------+------------+-------+--------+---------+

Column Removed

mysql> select * from class12;


+-----+-------+------------+-------+--------+
| rno | name | dob | marks | stream |
+-----+-------+------------+-------+--------+
| 101 | Arun | 2005-12-23 | 98 | biocs |
| 102 | raja | 2005-12-21 | 79 | biocs |
| 103 | arul | 2005-11-21 | 67 | biocs |
| 104 | anand | 2005-09-19 | 65 | biocs |
+-----+-------+------------+-------+--------+
4 rows in set (0.00 sec)

RESULT:
Thus, the above Python program is executed successfully and the output is verified

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy