[go: up one dir, main page]

0% found this document useful (0 votes)
18 views47 pages

CS Practical File

CS

Uploaded by

Sourav
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)
18 views47 pages

CS Practical File

CS

Uploaded by

Sourav
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/ 47

Page |1

INDEX
S.NO. TOPIC PAGE
NO.
1 8
To write a menu driven Python Program to perform
Arithmetic operations (+,-*,/) based on the user’s choice.

2 To write a Python Program to display Fibonacci Series up to ‘n’ 10


numbers

3 To write a menu driven Python Program to find Factorial and 12


sum of list of numbers using function

4 To Write a Python program to define the function Check(no1,no2) 14


that take two numbers and Returns the number that has
minimum ones digit.

5 15
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

6 To write a Python program to generate random number 16


between 1 to 6 to simulate the dice.

7 To write a Python Program to Read a text file "Story.txt" line by 17


line and display each word separated by '#'

8 To write a Python Program to read a text file "Story.txt" and


18
displays the number of Vowels/ Consonants/ Lowercase /
Uppercase/characters in the file.

9 To Write a method Disp() in Python, to read the lines 20


from poem.txt and display those words which are less
than 5 characters.

10 21
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'.
11 To write a Python Program to Create a binary file 22
with roll number and name. Search for a given roll
number and display the name, if not found display
appropriate message.

12 To write a Python Program to Create a binary file 24


with roll number, name, mark and update/modify the
mark for a given roll number.

13 26
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.

14 To write a Python program to implement Stack using a list data- 28


structure,
15 To Write a program, with separate user-defined functions 31
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
this 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).

16 To write a Python Program to integrate MYSQL with 33


Python to create Database and Table to store the details of
employees.

17 To write a Python Program to integrate MYSQL with 35


Python by inserting records to Emp table and display
the records.

18 To write a Python Program to integrate MYSQL with Python to 37


search an Employee using EMPID and display the record if
present in already existing table EMP, if not display the
appropriate message.
19 To write a Python Program to integrate MYSQL with Python to search 38
an Employee using EMPID and update the Salary of an employee
if present in already existing table EMP, if not display the
appropriate message
Page |3

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

Rollno Name Gender Age Dept DOA Fees


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

Rollno Name Gender Age Dept DOA Fees


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

Rollno Name Gender Age Dept DOA Fees


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

Rollno Name Gender Age Dept DOA Fees


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

24 To write Queries for the following Questions based on 47


the given table:
TABLE: UNIFORM

Ucode Uname Ucolor StockDate


1 Shirt White 2021-03-
31
2 Pant Black 2020-01-
01
3 Skirt Grey 2021-02-
18
4 Tie Blue 2019-01-
01
5 Socks Blue 2019-03-
19
6 Belt Black 2017-12-
09

TABLE: COST

Ucode Size Price Company


1 M 500 Raymond
1 L 580 Mattex
2 XL 620 Mattex
2 M 810 Yasin
2 L 940 Raymond
3 M 770 Yasin
3 L 830 Galin
4 S 150 Mattex
Page |5

CERTIFICATE
This is to certify that Sourav Dahiya, of class
XII B of RYAN INTERNATIONAL SCHOOL has
completed his Practical File under my
supervision. He has taken interest and
shown utmost sincerity in the completion of
this. I certify this Practical File up to my
expectations and as per the guidelines issued
by CBSE, NEW DELHI.

INTERNAL EXAMINER EXTERNALEXAMINER

PRINCIPAL
ACKNOWLEDGEMENT
It is with great pleasure that I express my sincere
gratitude to Ms. Ritu Dawar, our teacher, for her
valuable guidance and support throughout the
development of this project. Her dedication to teaching
and her constant encouragement have been a source of
inspiration not only for me but for all students. I have
greatly benefited from her classes and guidance.
I am deeply indebted to Ms. Mamta Nanda, our
Principal, whose continuous encouragement and
support have played a pivotal role in the success of this
project. Without her inspiration and belief in my
abilities, this project would not have been possible. I
extend my heartfelt thanks to her for her unwavering
support.
Lastly, I would like to express my sincere appreciation
to all my batch-mates for their friendship and for the
unforgettable moments we shared together. Their
presence has made this journey enjoyable and
memorable.
Page |7

HARDWARE AND SOFTWARE


REQUIREMENTS

Hardware Requirements:
• Processor: Intel Core i3 or equivalent
• RAM: 4 GB (8 GB recommended)
• Storage: 50 MB free disk space
• Display: 1024x768 resolution
• Input: Keyboard and Mouse
• OS: Windows 7 or higher, macOS, or Linux
Software Requirements:
• Programming Language: Python 3.6 or higher
• Libraries: datetime, csv, os, random
• IDE: Visual Studio Code, PyCharm, or any Python
IDE
• Database: CSV files for data storage
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 has been executed and the output is verified
successfully.
Page |9

SAMPLE OUTPUT:

Python Program Executed Output:

***************************************************************************************
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 has been executed and the output is verified
successfully.
P a g e | 11

SAMPLE OUTPUT:
Python Executed Program Output:

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

DATE:

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:

Result:
Thus, the above Python program has been executed and the output is verified
successfully.
P a g e | 13

SAMPLE OUTPUT:

Python Executed Program Output:

************************************************************************************************
EX.NO: 4

DATE:

CREATING A PYTHON PROGRAM TO IMPLEMENT RETURNING VALUE(S)


FROM FUNCTION

AIM:

To Write a Python program to define the function Check(no1,no2) that take two numbers and
Returns the number that has minimum ones digit.

Source Code:

Result:
Thus, the above Python program has been executed and the output is verified
successfully.

Sample Output:

**********************************************************************************
P a g e | 15

EX.NO: 5

DATE:

CREATING A PYTHON PROGRAM TO IMPLEMENT MATHEMATICAL FUNCTIONS

AIM:

To write a Python program to implement python mathematical functions to find:

(iv) To find Square of a Number.


(v) To find Log of a Number(i.e. Log10)
(vi) To find Quad of a Number

SOURCE CODE:

Result:
Thus, the above Python program has been executed and the output is verified
successfully.

SAMPLE OUTPUT:
Python Executed Program Output:

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

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 has been executed and the output is verified
successfully.

SAMPLE OUTPUT:

Python Executed Output Program:

**********************************************************************************
P a g e | 17

EX.NO: 7
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 display
each word separated by '#'.

SOURCE CODE:

Result:
Thus, the above Python program has been executed and the output is verified
successfully.

SAMPLE OUTPUT:
Story.txt:
EX.NO: 8

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 has been executed and the output is verified
successfully.
P a g e | 19

SAMPLE OUTPUT:
Story.txt:

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

CREATING PYTHON PROGRAM TO DISPLAY SHORT WORDS FROM A TEXT FILE

AIM:
To Write a method Disp() in Python, to read the lines from poem.txt and display those
words which are less than 5 characters.

Source Code:

Result:
Thus, the above Python program has been executed and the output is verified
successfully.

Sample Output:

Poem.txt:

Python Executed Program Output:

**********************************************************************************
P a g e | 21

EX.NO: 10

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 has been executed and the output is verified
successfully.

SAMPLE OUTPUT:

Python Executed Program output:


Sample.txt:

Python Executed Program Output:

New.txt:

*****************************************************************************************
EX.NO: 11
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 has been executed and the output is verified
successfully.
P a g e | 23

SAMPLE OUPUT:

PYTHON PROGRAM EXECUTED OUTPUT:

*******************************************************************************************
EX.NO: 12
DATE:

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:

Result:
Thus, the above Python program has been executed and the output is verified
successfully.
P a g e | 25

SAMPLE OUTPUT:

PYTHON PROGRAM EXECUTED OUTPUT:

**********************************************************************************
EX.NO: 13
DATE:

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:

Result:
Thus, the above Python program has been executed and the output is verified
successfully.
P a g e | 27

SAMPLE OUTPUT:

PYTHON PROGRAM EXECUTED OUTPUT:

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

CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(LIST)

AIM:
To write a Python program to implement Stack using a list data-structure, to perform

the following operations:

(i) To Push an object containing Doc_ID and Doc_name of doctors who specialize
in "ENT" to the stack.
(ii) To Pop the objects from the stack and display them.
(iii) To display the elements of the stack (after performing PUSH or POP)

SOURCE CODE:
P a g e | 29

Result:
Thus, the above Python program has been executed and the output is verified
successfully.

SAMPLE OUTPUT:
Python Program Executed Output:
****************************************************************************************
P a g e | 31

EX.NO: 15
DATE:

CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(Dictionary)

AIM:
To Write a program, with separate user-defined functions to perform the following
operations:
(iv) To Create a function Push(Stk,D) Where Stack is an empty list and D is Dictionary of
Items. from this Dictionary Push the keys (name of the student) into a stack,
where the corresponding value (marks) is greater than 70.
(v) 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.
(vi) To display the elements of the stack (after performing PUSH or POP).
Source Code:
Result:
Thus, the above Python program has been executed and the output is verified
successfully.

Sample Output:

*********************************************************************************
P a g e | 33

EX.NO: 16
DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(CREATING DATABASE AND TABLE)
AIM:
To write a Python Program to integrate MYSQL with Python to create Database and Table
to store the details of employees.

Source Code:

Result:
Thus, the above Python program has been executed and the output is verified
successfully.
Sample Output:

******************************************************************************************************
P a g e | 35

EX.NO: 17
DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(INSERTING RECORDS AND DISPLAYING RECORDS)

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 has been executed and the output is verified
successfully.
SAMPLE OUTPUT:

Python Executed Program Output:

******************************************************************************************************************************************************************************
P a g e | 37

EX.NO: 18

DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(SEARCHING AND DISPLAYING RECORDS)
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 has been executed and the output is verified
successfully.

SAMPLE OUTPUT:

Python Executed Program Output:


EX.NO: 19
DATE:

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 has been executed and the output is verified
successfully.
P a g e | 39

SAMPLE OUTPUT:

Python Executed Program Output:

**************************************************************************************************************************************************
SQL COMMANDS EXERCISE - 1
Ex.No: 20
DATE:

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".

CREATE DATABASE STUDENTS;

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

USE STUDENTS;

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

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.

SHOW DATABASES;

(e) Write a Query to List all the tables that exists in the current database.

SHOW TABLES;
Output:
P a g e | 41

SQL COMMANDS EXERCISE - 2


Ex.No: 21
DATE:

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 insert all the rows of above table into Info table.

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

(b) Write a Query to display all the details of the Employees from the above table 'STU'.

SELECT * FROM STU;

Output:
(c) Write a query to Rollno, Name and Department of the students from STU table.

SELECT ROLLNO,NAME,DEPT FROM STU;

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

SELECT DISTICT(DEPT) FROM STU;

Output:

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

SELECT * FROM STU WHERE DEPT='HISTORY';

Output:

********************************************************************************************
P a g e | 43

Ex.No: 22 SQL COMMANDS EXERCISE - 3

DATE:

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 list name of female students in Hindi Department.

SELECT NAME FROM STU WHERE DEPT='HINDI' AND GENDER='F';

Output:

(b) Write a Query to list name of the students whose ages are between 18 to 20.

SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;

Output:
(c) Write a Query to display the name of the students whose name is starting with 'A'.

SELECT NAME FROM STU WHERE NAME LIKE 'A%';

Output:

(d) Write a query to list the names of those students whose name have second alphabet 'n' in their
names.

SELECT NAME FROM STU WHERE NAME LIKE '_N%';

Output:

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

39
P a g e | 45

Ex.No: 23 SQL COMMANDS EXERCISE - 4

DATE:

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.

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.

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.

ALTER TABLE STU ADD AREA VARCHAR(20);

Output:

(d) Write a Query to Display Name of all students whose Area Contains NULL.

SELECT NAME FROM STU WHERE AREA IS NULL;

Output:

(e) Write a Query to delete Area Column from the table STU.

ALTER TABLE STU DROP AREA;

Output:

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

DROP TABLE STU;

Output:
*******************************************************************************************
Ex.No: 24 SQL COMMANDS EXERCISE - 5
DATE:

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

Ucode Uname Ucolor StockDate


1 Shirt White 2021-03-31
2 Pant Black 2020-01-01
3 Skirt Grey 2021-02-18
4 Tie Blue 2019-01-01
5 Socks Blue 2019-03-19
6 Belt Black 2017-12-09

TABLE: COST

Ucode Size Price Company


1 M 500 Raymond
1 L 580 Mattex
2 XL 620 Mattex
2 M 810 Yasin
2 L 940 Raymond
3 M 770 Yasin
3 L 830 Galin
4 S 150 Mattex

(a) To Display the average price of all the Uniform of Raymond Company from table COST.

SELECT AVG(PRICE) FROM COST WHERE COMPANY='RAYMOND';

Output:

(b) To display details of all the Uniform in the Uniform table in descending order of Stock date.

SELECT * FROM UNIFORM ORDER BY STOCKDATE DESC;

Output:

You might also like