0% found this document useful (0 votes)
76 views

Computer Practical Class 12 by - Manish

The document contains 15 Python programs with their aims, source codes, and sample outputs. The programs cover topics like arithmetic operations using menus, Fibonacci series, factorials and list sums using functions, mathematical functions, random number generation, reading and parsing text files, binary and CSV file operations, stack implementation, and MySQL integration for insert, search, update operations. It also contains 16 SQL queries on a sample student database table to create the database and table, and retrieve data based on various conditions.

Uploaded by

gamingmsop5
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Computer Practical Class 12 by - Manish

The document contains 15 Python programs with their aims, source codes, and sample outputs. The programs cover topics like arithmetic operations using menus, Fibonacci series, factorials and list sums using functions, mathematical functions, random number generation, reading and parsing text files, binary and CSV file operations, stack implementation, and MySQL integration for insert, search, update operations. It also contains 16 SQL queries on a sample student database table to create the database and table, and retrieve data based on various conditions.

Uploaded by

gamingmsop5
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 40

lOMoARcPSD|27774220

Program 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.
lOMoARcPSD|27774220

SOURCE CODE:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

Python Program Executed


Output: Run – 1:

RUN- 2

*************************************************************************************
lOMoARcPSD|27774220

Program No: 2

CREATING A PYTHON PROGRAM TO DISPLAY FIBONACCI SERIES

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

SOURCE CODE:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

Python Executed Program Output:

RUN -1:

RUN -2 :

*****************************************************************************************
lOMoARcPSD|27774220

Program No: 3

CREATING A MENU DRIVEN PROGRAM TO FIND FACTORIAL AND SUM OF LIST OF


NUMBERS USING FUNCTION.

AIM:

To write a menu driven Python Program to find Factorial and sum of list of numbers
using function.

SOURCE CODE:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

Python Executed Program


Output: RUN -1:

RUN – 2:

**************************************************************************************
lOMoARcPSD|27774220

Program No: 4
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:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

Python Executed Program Output:

**************************************************************************************
lOMoARcPSD|27774220

Program No: 5

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:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

Python Executed Output Program:

**************************************************************************************
lOMoARcPSD|27774220

Program No: 6
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 display
each word separated by '#'.

SOURCE CODE:
lOMoARcPSD|27774220

SAMPLE OUTPUT:
Story.txt:

***************************************************************************************
lOMoARcPSD|27774220

Program No: 7
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:
lOMoARcPSD|27774220

SAMPLE OUTPUT:
Story.txt:

***************************************************************************************
lOMoARcPSD|27774220

Program No: 8
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:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

Python Executed Program


output: Sample.txt:

Python Executed Program Output:

New.txt:

*****************************************************************************************
lOMoARcPSD|27774220

Program No: 9
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:
lOMoARcPSD|27774220

SAMPLE OUPUT:

PYTHON PROGRAM EXECUTED OUTPUT:

*******************************************************************************************
lOMoARcPSD|27774220

Program No: 10
CREATING A PYTHON PROGRAM TO CREATE AND UPDATE/MODIFY RECORDS IN
BINARY FILE

AIM:
To write a Python Program to Create a binary file with roll number, name, mark
and update/modify the mark for a given roll number.

SOURCE CODE:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

PYTHON PROGRAM EXECUTED OUTPUT:

**********************************************************************************
lOMoARcPSD|27774220

Program No: 11
CREATING A PYTHON PROGRAM TO CREATE AND SEARCH EMPLOYEE’S RECORD
IN CSV FILE.

AIM:

To write a Python program 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:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

PYTHON PROGRAM EXECUTED OUTPUT:

******************************************************************************
lOMoARcPSD|27774220

Program No: 12

CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS

To write a Python program to implement Stack using a list data-structure.


AIM:
SOURCE CODE:
lOMoARcPSD|27774220

SAMPLE OUTPUT:
Python Program Executed Output:
lOMoARcPSD|27774220

****************************************************************************************
lOMoARcPSD|27774220

Program No: 13

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON


AIM: (INSERTING RECORDS AND DISPLAYING RECORDS)

To write a Python Program to integrate MYSQL with Python by inserting records to


Emp table and display the records.

SOURCE CODE:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

Python Executed Program Output:

SQL OUTPUT:
lOMoARcPSD|27774220

Program No: 14

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON


AIM: (SEARCHING AND DISPLAYING RECORDS)

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:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

Python Executed Program

Output: RUN -1:

Run – 2:

SQL OUTPUT:

OUTPUT -1:

OUTPUT -2:
lOMoARcPSD|27774220

Program No: 15

CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON


AIM: (UPDATING RECORDS)

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:
lOMoARcPSD|27774220

SAMPLE OUTPUT:

Python Executed Program

Output: RUN -1:

Run -2:

SQL OUTPUT:
lOMoARcPSD|27774220

SQL COMMANDS EXERCISE - 1


Program No: 16

AIM:
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to Create a new database in the name of "STUDENTS"

Sol:mysql> CREATE DATABASE STUDENTS;

(b) Write a Query to Open the database "STUDENTS"

Sol:mysql> USE STUDENTS;

(c) Write a Query to create the above table called: Info

Sol:

mysql> CREATE TABLE STU(Rollno int Primary key,Name varchar(10),Gender varchar(3),


Age int,Dept varchar(15),DOA date,Fees int);

(d) Write a Query to list all the existing database names.


Sol:
mysql> SHOW DATABASES;
Output:
lOMoARcPSD|27774220

(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);

INSERT INTO STU VALUES (2,'Ankit','M', 21,'HISTORY','1998-03-24', 200);

INSERT INTO STU VALUES (3,'Anu','F', 20,'HINDI','1996-12-12', 300);

INSERT INTO STU VALUES (4,'Bala','M', 19, NULL,'1999-07-01', 400);

INSERT INTO STU VALUES (5,'Charan','M', 18,'HINDI','1997-06-27', 250);

INSERT INTO STU VALUES (6,'Deepa','F', 19,'HISTORY','1997-06-27', 300);

INSERT INTO STU VALUES (7,'Dinesh','M', 22,'COMPUTER','1997-02-25', 210);

INSERT INTO STU VALUES (8,'Usha','F', 23, NULL,'1997-07-31', 200);

(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;
lOMoARcPSD|27774220

Program No: 17 SQL COMMANDS EXERCISE – 2

AIM:
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to select distinct Department from STU table.


Sol:
mysql> SELECT DISTICT(DEPT) FROM STU;

Output:

(b) To show all information about students of History department.


Sol:

mysql>SELECT * FROM STU WHERE DEPT='HISTORY';

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';

Output:
lOMoARcPSD|27774220

(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%';

********************************************************************************************************
lOMoARcPSD|27774220

Program No: 18 SQL COMMANDS EXERCISE - 3

AIM:
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to delete the details of Roll number is 8.


Sol:

mysql> DELETE FROM STU WHERE ROLLNO=8;

Output (After Deletion):

(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):
lOMoARcPSD|27774220

(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:

(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:

(f) Write a Query to delete table from Database.

Sol:
mysql> DROP TABLE STU;

Output:

*******************************************************************************************
lOMoARcPSD|27774220

Program No: 19 SQL COMMANDS EXERCISE - 4

AIM:
To write Queries for the following Questions based on the given table:
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:
lOMoARcPSD|27774220

(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:

*************************************************************************************************

You might also like