CS 12 1
CS 12 1
SCHOOL
COMPUTER SCIENCE
PRACTICAL FILE
2
CREATING A PYTHON PROGRAM TO IMPLEMENT STACK
15 33
OPERATIONS
3
EX.NO: 1
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 veri ied.
4
OUTPUT
SAMPLE OUTPUT:
RUN- 2
***************************************************************************************
5
EXPERIMENT
EX.NO: 2
AIM:
To write a Python Program to display Fibonacci Series up to ‘n’ numbers.
SOURCE CODE:
6
OUTPUT
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
RUN -1:
RUN -2:
*****************************************************************************************
7
EXPERIMENT
EX.NO: 3
AIM:
To write a menu driven Python Program to ind Factorial and sum of list of numbers using
function.
SOURCE CODE:
8
OUTPUT
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
RUN -1:
RUN – 2:
**************************************************************************************
9
EXPERIMENT
EX.NO: 4
AIM:
To write a Python program to implement python mathematical functions to ind:
SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
10
OUTPUT
**************************************************************************************
11
EXPERIMENT
EX NO: 5
USER DEFINED FUNCTIONS WITH PARAMETERS
AIM:
Program to ind simple interest using a user de ined function with parameters and with
return value.
SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
12
OUTPUT
SAMPLE OUTPUT:
**************************************************************************************
13
EXPERIMENT
EX.NO: 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 veri ied.
14
OUTPUT
SAMPLE OUTPUT:
Python Executed Output Program:
**************************************************************************************
15
EXPERIMENT
EX.NO: 7
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 ile "Story.txt" line by line and display each word
separated by '#'.
SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
SAMPLE OUTPUT:
Story.txt:
16
OUTPUT
***************************************************************************************
17
EXPERIMENT
EX.NO: 8
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 ile "Story.txt" and displays the number of Vowels/
Consonants/ Lowercase / Uppercase/characters in the ile.
SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
18
OUTPUT
SAMPLE OUTPUT:
Story.txt:
***************************************************************************************
19
EXPERIMENT
EX.NO: 9
AIM:
To write a python program to read lines from a text ile "Sample.txt" and copy those lines into another ile
which are starting with an alphabet 'a' or 'A'.
SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
20
OUTPUT
OUTPUT:
Python Executed Program output:
Sample.txt:
New.txt:
*****************************************************************************************
21
EXPERIMENT
EX.NO: 10
DATE:
AIM:
To write a Python Program to Create a binary ile with roll number and name. Search for a given
roll number and display the name, if not found display appropriate message.
SOURCE CODE:
22
OUTPUT
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
OUPUT:
*******************************************************************************************
23
EXPERIMENT
EX NO: 11
CREATING A PYTHON PROGRAM TO CREATE AND UPDATE/MODIFY RECORDS IN
BINARY FILE
AIM:
To write a Python Program to Create a binary ile with roll number, name, mark and
update/modify the mark for a given roll number.
SOURCE CODE:
24
OUTPUT
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
OUTPUT:
**********************************************************************************
25
EXPERIMENT
EX NO: 12
AIM:
To write a Python program Create a CSV ile to store Empno, Name, Salary and search any Empno
and display Name, Salary and if not found display appropriate message.
SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
26
OUTPUT
OUTPUT:
******************************************************************************
27
EXPERIMENT
EX NO: 13
AIM:
SOURCE CODE:
28
OUTPUT
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
SAMPLE OUTPUT:
Python Program Executed Output:
29
OUTPUT
****************************************************************************************
30
EXPERIMENT
EX.NO: 14
AIM:
Write a program to implement a stack for the employee details (empno, name).
SOURCE CODE:
31
OUTPUT
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
SAMPLE OUTPUT:
32
EXPERIMENT
EX.NO: 15
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
AIM:
To write a Python Program to integrate MYSQL with Python by inserting records to Emp table and
display the records.
SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
33
OUTPUT
SAMPLE OUTPUT:
SQL OUTPUT:
34
EXPERIMENT
EX.NO: 16
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
AIM:
To write a Python Program to integrate MYSQL with Python to search an Employee using EMPID
and display the record if present in already existing table EMP, if not display the appropriate
message.
SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
SAMPLE OUTPUT:
RUN -1:
35
OUTPUT
Run – 2:
SQL OUTPUT:
OUTPUT -1:
OUTPUT -2:
36
EXPERIMENT
EX.NO: 17
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(UPDATING RECORDS)
AIM:
To write a Python Program to integrate MYSQL with Python to search an Employee using EMPID
and update the Salary of an employee if present in already existing table EMP, if not display the
appropriate message.
SOURCE CODE:
Result:
Thus, the above Python program is executed successfully and the output is veri ied.
SAMPLE OUTPUT:
37
OUTPUT
RUN -1:
Run -2:
SQL OUTPUT:
38
EXPERIMENT
AIM:
To write Queries for the following Questions based on the given table:
Sol:
mysql> CREATE TABLE STU(Rollno int Primary key,Name varchar(10),Gender varchar(3), Age int,Dept
varchar(15),DOA date,Fees int);
39
OUTPUT
(e) Write a Query to List all the tables that exists in the current database.
Sol:
mysql> SHOW TABLES; Output:
(f) Write a Query to insert all the rows of above table into Info table.
Sol:
INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);
(g) Write a Query to display all the details of the Employees from the above table 'STU'.
Sol:
mysql> SELECT * FROM STU;
Output:
(h) Write a query to Rollno, Name and Department of the students from STU table.
Sol:
mysql> SELECT ROLLNO,NAME,DEPT FROM STU;
40
EXPERIMENT
EX NO: 19
AIM:
To following Questions based on the given
(a) Write a Query to select distinct Department from STU table. Sol:
mysql> SELECT DISTICT(DEPT) FROM STU;
Output:
Output:
(c) Write a Query to list name of female students in Hindi Department. Sol:
mysql> SELECT NAME FROM STU WHERE DEPT='HINDI' AND GENDER='F';
41
OUTPUT
Output:
(d) Write a Query to list name of the students whose ages are between 18 to 20. Sol:
mysql> SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;
Output:
(e) Write a Query to display the name of the students whose name is starting with 'A'. Sol:
mysql> SELECT NAME FROM STU WHERE NAME LIKE 'A%';
Output:
(f) Write a query to list the names of those students whose name have second alphabet 'n' in their names. Sol:
mysql> SELECT NAME FROM STU WHERE NAME LIKE '_N%';
42
EXPERIMENT
EX NO: 20
AIM:
To following Questions based on the given
(b) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the existing fess is less than
130.
Sol:
mysql> UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130;
Output(After Update):
(c) Write a Query to add a new column Area of type varchar in table STU.
Sol:
mysql> ALTER TABLE STU ADD AREA VARCHAR(20);
Output:
43
OUTPUT
(d) Write a Query to Display Name of all students whose Area Contains NULL.
Sol:
mysql> SELECT NAME FROM STU WHERE AREA IS NULL;
Output:
(e) Write a Query to delete Area Column from the table STU.
Sol:
mysql> ALTER TABLE STU DROP AREA;
Output:
Sol:
mysql> DROP TABLE STU;
Output:
44
EXPERIMENT
EX NO: 21
AIM:
To following Questions based on the given
TABLE: STOCK
Pno Pname Dcode Qty UnitPrice StockDate
5005 Ball point pen 102 100 10 2021-03-31
5003 Gel pen premium 102 150 15 2021-01-01
5002 Pencil 101 125 4 2021-02-18
5006 Scale 101 200 6 2020-01-01
5001 Eraser 102 210 3 2020-03-19
5004 Sharpner 102 60 5 2020-12-09
5009 Gel pen classic 103 160 8 2022-01-19
TABLE: DEALERS
Dcode Dname
101 Sakthi Stationeries
103 Classic Stationeries
102 Indian Book House
(a) To display the total Unit price of all the products whose Dcode as 102.
Sol:
mysql> SELECT SUM(UNITPRICE) FROM STOCK GROUP BY DCODE HAVING DCODE=102;
Output:
(b) To display details of all products in the stock table in descending order of Stock date.
Sol:
mysql> SELECT * FROM STOCK ORDER BY STOCKDATE DESC;
Output:
45
OUTPUT
(c) To display maximum unit price of products for each dealer individually as per dcode from the table
Stock.
Sol:
mysql> SELECT DCODE,MAX(UNITPRICE) FROM STOCK GROUP BY DCODE;
Output:
(d) To display the Pname and Dname from table stock and dealers.
Sol:
mysql> SELECT PNAME,DNAME FROM STOCK S,DEALERS D WHERE S.DCODE=D.DCODE;
Output:
46
EXPERIMENT
AIM:
To write Queries for the following Questions :
a. Write a query to display cube of 5.
b. Write a query to display the number 563.854741 rounding off to the next hundred.
c. Write a query to display "put" from the word "Computer".
d. Write a query to display today's date into DD.MM.YYYY format.
e. Write a query to display 'DIA' from the word "MEDIA".
Sol:
a. select pow(5,3);
b. select round(563.854741,-2);
c. select mid(“Computer”,4,3);
47
OUTPUT
e. select right("Media",3);
48