0% found this document useful (0 votes)
2 views35 pages

Sample CS Practical File

This document is a practical file for a Computer Science course at Lucknow Public School, detailing various programming tasks and concepts. It covers user-defined functions, file handling (text, binary, CSV), data structures (stack), and Python-MySQL connectivity, with specific programs and source code examples for each topic. Additionally, it includes SQL queries based on provided tables, demonstrating database manipulation skills.

Uploaded by

hemlata08mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views35 pages

Sample CS Practical File

This document is a practical file for a Computer Science course at Lucknow Public School, detailing various programming tasks and concepts. It covers user-defined functions, file handling (text, binary, CSV), data structures (stack), and Python-MySQL connectivity, with specific programs and source code examples for each topic. Additionally, it includes SQL queries based on provided tables, demonstrating database manipulation skills.

Uploaded by

hemlata08mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

PRACTICAL FILE

COMPUTER SCIENCE
SUBJECT CODE: 083

LUCKNOW PUBLIC SCHOOL


SEC-D, LUCKNOW
SESSION: 2025-
26
SUBMITTED TO : MS. NEHA MISHRA
SUBMITTED BY :

ROLL NO.
INDEX
NO. OF
S.NO. TOPIC QUESTIONS

1. USER DEFINED FUNCTIONS 04

2. FILE HANDLING OF TEXT FILES 04

3. FILE HANDLING OF BINARY FILES 04

4. FILE HANDLING OF CSV FILES 04

5. DATA STRUCTURE- STACK 02

6. PYTHON - MYSQL CONNECTIVITY 04

7. SQL QUERIES 10

Subject Teacher: Date:

Page | 2
USER-DEFINED
FUNCTIONS

Page | 3
PROGRAM
-1
Write a Python function SwitchOver(VAL) to swap the even and odd
positions values in the list VAL.
Source Code:-
def SwitchOver(VAL):
for i in range(0,len(VAL),1):
if i%2==0:
VAL[i],VAL[i+1]=VAL[i+1],VAL[i]
i=i+1
print('List after swapping is:',VAL)

lst=[1,2,3,4,5,6]
print('List is:',lst)
SwitchOver(lst)

OUTPUT:-

Page | 4
PROGRAM
-2
Write a Python function HowMany(ID,Val) to count and display
number of times the value of Val is present in the list ID.

SourceCode:-

OUTPUT:-

Page | 5
PROGRAM
-3
Write a Python function FindOut(Names, HisName) to search for
HisName string from a list Names, and display the position of its
presence.
Source Code:-

OUTPUT:-

Page | 6
PROGRAM
-4
Write a Python function EndingA(Names) to search and display those
strings from the list of Names, which are ending with 'a'.

Source Code:-

OUTPUT:-

Page | 7
FILE HANDLING OF
TEXT FILES

Page | 8
PROGRAM
-5
Write a function BIGWORDS() in Python to read contents from a text
file CODE.TXT, to count and display the occurrence of those words,
which are having 5 or more alphabets.
Source Code:-

OUTPUT:-

Page | 9
PROGRAM
-6
Write a function ISTOUPCOUNT() in python to read contents from a
text file WRITER.TXT, to count and display the occurrence of the word
“IS” or “TO” or “UP”.
Enter city =Lucknow
SOURCE CODE:-

OUTPUT:-

Page | 10
PROGRAM
-7
Write a function AEDISP() in python to read lines from a text file
WRITER.TXT, and display those lines, which are starting either with A
or starting with E.
Source Code:

Output:

Page | 11
PROGRAM
-8
Write a function COUNTUPPER() to count uppercase alphabets
present in a file ‘article.txt’

Source Code:

Output:

Page | 12
FILE HANDLING OF
BINARY FILES

Page | 13
PROGRAM
-9
Write a Python function STORE() to get student data (rollno, name,
and %marks) of 3 students from user and write it onto a binary file
‘stu.dat’.

Source Code:

OUTPUT;

Page | 14
PROGRAM -
10
Write a function GETDATA() to read student records from binary file
‘stu.dat’ and display only those records where percentage marks are
between 70% and 85%(both limits included)

Source Code:

OUTPUT:

Page | 15
PROGRAM
- 11
Write a function to write records of 3 employees (empno, ename, age)
in a binary file ‘emp.dat’ and also read and display only those records
where employee’s age is 25 or above.

Source Code:

OUTPUT:

Page | 16
Page | 17
PROGRAM -
12
Write a function to search and display details of all trains whose
destination is ‘Delhi’ from a binary file ‘train.dat’. Assuming the binary
file is containing the objects of following dictionary type:
Train={‘tno’:____, ‘from’:_____, ‘to’:______}

SOURCE CODE:

OUTPUT:

Page | 18
FILE HANDLING OF
CSV FILES

Page | 19
PROGRAM -
13
WAP to create a CSV file ‘marks.csv’ and store data (rollno, name,
marks) of 3 students in that file by suppressing the EOL translation.

Source Code:-

OUTPUT:

Page | 20
PROGRAM -
Source Code:- 14

Output:

Page | 21
PROGRAM
-15
WAF that reads the contents of csv file ‘schools.csv’ and creates
another file ‘backup.csv’ with the same contents but with a different
delimiter.
Source Code:

Output:

Page | 22
PROGRAM
-16
WAF to read the contents of file “countries.csv” and copy only those
records to ‘icountry.csv’ where country name starts with ‘i’.

Source Code:

Output:

Page | 23
DATA STRUCTURE -
STACK

Page | 24
PROGRAM
Anjali has created a list containing salary of 5 employees.
sal=[5000,6500,7000,4500,6000]
Write user-defined functions for the following:
(i) to traverse the list and push only salary of those employees into
stack where salary is below 6500.
(ii) to pop and display the contents of the stack.

SOURCE CODE –

OUTPUT:-

Page | 25
PROGRAM -
17
Julia has created a dictionary containing names and marks as key
value pairs of 6 students. Write a program, with separate user defined
functions to perform the following operations:
(i) Push the keys (name of the student) of the dictionary into a stack,
where the corresponding value (marks) is greater than 75.
(ii) Pop and display the content of the stack.

SOURCE CODE –

OUTPUT:

Page | 26
PYTHON-MYSQL
CONNECTIVITY

Page | 27
PROGRAM -
WAP to fetch and display all rows from table EMPL present in
database ‘menagerie’.
SOURCE CODE:
23

OUTPUT:-

Page | 28
PROGRAM
- 24
WAP to take input of deptno and job from user, fetch & display
records accordingly from table EMPL created in menagerie database.

SOURCE CODE:

OUTPUT:

Page | 29
PROGRAM -
WAP to fetch and display only those rows from table STUDENT
present in database ‘menagerie’ where CLASS is 12 and section is
25
‘A’.The table STUDENT consists of following structure:
Field Name Datatype & Size
Rollno Int(4)
Name Varchar(20)
Class Int(2)
Section Char(1)
DOB Date

DATA IN TABLE STUDENT:-


Rollno Name Class Section DOB
101 Ravi 12 A 2010-12-23
102 Hari 12 B 2011-05-12
103 Om 12 A 2010-06-13
104 Pooja 12 C 2009-09-18
105 Sejal 12 B 2010-06-02
SOURCE CODE:

OUTPUT:

Page | 30
PROGRAM -
26
Write a function to fetch and display only first 3 rows from table EMPL
present in database ‘menagerie’.

SOURCE CODE:

OUTPUT:

Page | 31
SQL
QUERIES

Page | 32
Given the following two tables:

Table :
Persons
Empno Name DOB City Hobby
123 Amit 23-jan-1965 Delhi Music
127 Manoj 12-dec-1976 Mumbai Writing
124 Vinod 11-aug-1975 Allahabad Music
125 Anita 4-apr-1977 Delhi Sports
128 Abhay 10-mar-1974 Mumbai Gardening
129 Ramesh 28-oct-1981 Pune Sports

Table :
Empno

123
Area

Agra Job
App_date

25-jan-2006
Salary

5000
Retd_date

25-jan-2026
Dept

Marketing
127 Mathura 22-dec-2006 6000 22-dec-2026 Finance
124 Agra 19-aug-2007 5500 19-aug-2027 Marketing
125 Delhi 14-apr-2004 8500 14-apr-2018 Sales
128 Pune 13-mar-2008 7500 13-mar-2028 Sales

Write SQL commands for the following queries based on tables


‘PERSONS’ and ‘JOB’.

i) To display empno, name and hobby of those persons who have


sports as hobby and name starts with ‘A’.

ii) To display all persons in decreasing order of appointment date.

iii)To display no. of persons area wise.

Page | 33
iv) To display youngest person from each city.

v) To display empno, name ,hobby and salary of persons working in


Marketing department.

vi) To display name, appointment date and salary of those persons of


Agra region.

vii) To display salary of those persons who shall retire after 20-jan-
2006.

viii) To increase the salary of employees of Sales department by 10%.

ix) To add a new column GRADE of type CHAR and size 1 in table Job.

x) To remove the records of persons of Delhi area.

xi) To display max. salary of each department.

xii) To display total salary of each department where the total salary
is more than 12000.

xiii) To display no. of departments.

xiv) To display count of persons working in different departments.

xv) To display average salary of persons working in Delhi and


Mumbai.

Queries:-

Page | 34
Page | 35

You might also like