CS Practical Record 24-25
CS Practical Record 24-25
Teacher In-charge
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
Aim:
Source Code:
Result:
Thus, the above program has been executed and the output is verified successfully.
Output :
1
DATE : PROGRAM NO : 2
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
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
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
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.
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.
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
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
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
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> 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)
29
Displaying a table:
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)
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;
Delete Command
Drop Command
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
SQL Commands:
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
Name
Shriya
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
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
SQL Commands:
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));
35
OUTPUT:
36
3. Select * from student where stream like ‘Science’;
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
TABLE : CUSTOMER
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:
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));
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 :
NAME
NEHA SONI
NAME
SONY
ONIDA
NOKIA
DELL
BLACKBERRY
39
3. update customer set price = price + 1000 where name like ‘s%’;
select * from customer;
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:
CREATE TABLE DOCTOR(ID int NOT NULL PRIMARY KEY, NAME char(25) , DEPT char(25) ,
SEX char , EXPERIENCE int);
CREATE TABLE SALARY(ID int, BASIC int, ALLOWANCE int, CONSULTATION int);
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:
42
2. select avg(BASIC+ALLOWANCE) as “avg salary” from DOCTOR , SALARY
where DOCTOR.ID=SALARY.ID and DEPT=”ENT”;
RESULT:
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”)
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