Practical Record 2023-24
Practical Record 2023-24
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:
RUN- 2
***************************************************************************************
EX.NO: 2
DATE:
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:
RUN -1:
RUN -2 :
*****************************************************************************************
EX.NO: 5
DATE:
AIM:
SOURCE CODE:
RESULT:
Thus, the above Python program is executed successfully and the output is verified.
SAMPLE OUTPUT:
**************************************************************************************
EX.NO: 6
DATE:
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:
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:
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:
**************************************************************************************
EX.NO: 11
DATE:
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:
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:
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:
************************************************************************************
EX.NO: 16
DATE:
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:
DATE:
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:
New.txt:
*****************************************************************************************
EX.NO: 3
DATE:
AIM:
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:
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 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 modify the size of the column “studentname” in the existing Table “student”
mysql> ALTER TABLE STUDENT
-> MODIFY STUDENTNAME VARCHAR(25);
To update PHYSICS and MATHS subject marks of students in the Table “student”
mysql> UPDATE STUDENT
-> SET PHYSICS=67,MATHS=78
-> WHERE ROLLNO=1;
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:
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:
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:
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:
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>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....!
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:
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)
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
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
Column Removed
RESULT:
Thus, the above Python program is executed successfully and the output is verified