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

CS Programmes

Uploaded by

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

CS Programmes

Uploaded by

nakiimam03
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 69

D.A.

V public school
ashok vihar phase-iv delhi

Computer
science
With Python

Practicle file
Session[2023-2024]
Name: Naki Imam
Class: XII-A
Roll No. :
INDEX OF COMPUTER SCIENCE
PRACTICAL FILE

01 Revision tour
02 function

Data file handling Stack


03 •


Text File
Binary File
CSV File
04 implementation

05 Databases 06 Interface Python


SQL Connectivity
INTRODUCTION
This practical file serves as a comprehensive guide for exploring computer science
concepts
and implementing them using the Python programming language. Through a series
of hands
on exercises and projects, this practical file aims to enhance our understanding of
computer
science principles and strengthen our programming skills. Python, a versatile and
beginner-
friendly programming language, has gained immense popularity in the field of
computer
science due to its simplicity, readability, and extensive libraries. It provides a
Revision tour

This chapter deals with all the concept taught in class 11 that are basic for
python language

1. Program to sort a list

2. Program to shift negative elements on one side in list

3. Program to add ‘n’ number of items in list

4. Program to find largest and second largest no. from list

5. Program to input two tuples and swap their values

6. Program to perform linear search on tuple


Program to input a tuple of integers & find the maximum & minimum integer from the
7.
tuple
8. Program to count no. of occurrence of character in given string using dictionary
Function

This chapter deals with defining and creating sub programs and functions

1. Finding area of different shapes using functions

2. Finding factorial using functions

3. Counting lowercase and uppercase characters using functions

4. Counting vowels in a string using functions


Text file

This chapter deals with programs libraries modules related to text file

1. Program to read & print the lines having length more than 50 in text files

2. Program to count no. of words in text files

3. Program to count no. of vowels, consonants & digits in text files

4. Program to count words starting with ‘P’ or ‘E’ in text files

5. Find the total no. of lines & total no. of words in a text file

6. Program to read & print the words having length more than 7 from text file

7. Program to make a employee record in a text file using writelines ()

8. Program to make a copy file of only those lines starting with uppercase letters
Program to append employees in the record and search those employees having salary
9.
more than 15000
binary file

This chapter deals with programs libraries modules related to binary file

1. Program for writing & reading students’ record in a binary file. (METHOD-1)

2. Program for writing & reading students’ record in a binary file. (METHOD-2)

3. Program to make a dictionary in binary files

4. Program to make a book record in binary files

5. Program for appending record in a binary file

6. Program for deleting a record in a binary file

7. Program for updating a record in a binary file

8. Program to store Gmeet Info in binary files


Csv file

This chapter deals with the CSV files

1. Program to reading the csv file.

2. Program to display vowels present in the words entered by user

3. Program to push, pop , and display name and ID of the book in stack of book

4. Program to push,pop & display name and marks of students in stack of students
STACK
IMPLEMENTATION
This chapter deals with the new algorithms

1. Program to showcase all functions of stack

2. Program to store students data in csv file

3. Program to search a student’s record

4. Program to write in a csv file using writerow() function


DATABASE

SQL (Structured Query Language) is a domain-specific language used for managing and
querying relational databases, facilitating data storage, retrieval, and manipulation.

1. Database containing LOANS table

2. Database containing PRODUCT & CLIENT table

3. Database containing COMPANY & MODEL table

4. Database containing STOCK & DEALER table

5. Database containing CARDEN table

6. DATABASE CONNECTIVITY
01

REVISION TOUR
Sort a list

Source code output


Program to shift negative elements
on one side in list

Source code output


Program to add ‘n’ number of
items in list

Source code output


Program to find largest and
second largest no. from list

Source code output


Program to input two tuples and
swap their values

Source code output


Program to perform linear
search on tuple

Source code output


Program to input a tuple of integers &
find the maximum & minimum integer
from the tuple

Source code output


Program to count no. of occurrence of
character in given string using
dictionary

Source code output


02

FUNCTION
Finding area of different
shapes using functions

Source code output


Finding factorial using
functions

Source code output


Counting vowels in a string
using functions

Source code output


Counting lowercase and
uppercase characters using
functions

Source code output


03

TEXT FILE
Program to read & print the lines
having length more than 50 in
text files

output

Source code Text File


Program to count no.
of words in text files

output

Source code Text


output
File
Program to count no. of vowels,
consonants & digits in text files

output

Source code Text File


Program to count words starting
with ‘P’ or ‘E’ in text files

output

Source code Text File


Find the total no. of
lines & total no. of
words in a text file

output

Source code Text File


Program to read & print the
words having length more than
7 from text file

output

Source code Text File


Program to make a employee
record in a text file using
writelines ()

output

Source code Text File


Program to make a copy file of
only those lines starting with
uppercase letters

Copied file

Source code Text File


Program to append employees in the
record and search those employees
having salary more than 15000

output

Source code Text File


04

BINARY FILE
Program for writing &
reading students’ record in a
binary file. (METHOD-1)

Source code output


Program for writing & reading
students’ record in a binary
file. (METHOD-2)

Source code output


Program to make a
dictionary in binary files

Source code output


Program to make a
book record in binary
files

Source code output


Program for appending
record in a binary file

Initial
Entries

Source code output


Program for deleting a
record in a binary file

output

Initial
Source code entries
Program for updating
a record in a binary
file

output

Initial file
Source code data
Program to store Gmeet
Info in binary files

Source code output


05

CSV FILE
Program to reading a
csv file

Source code output


Program to store
students data in csv file

output

Source code CSV FILE


Program to search a
student’s record

Source code output


Program to write in a csv
file using writerow()
function

output

Source code CSV FILE


06
STACK
IMPLEMENTATION
Program to showcase all
functions of stacks

Source code output


Program to display vowels
present in the words entered by
user

Source code output


Program to push, pop & display
name and Id of the book in
stack of book

Source code output


07

DATABASES
LOANs TABLE

AccNo. Cust_Name Loan_Amoun Installmen Int_Rate Start_Date Interest


t ts

1. R.K. Gupta 30000 36 12.00 2009-07-19 1200

2. S.P. Sharma 50000 48 10.00 2008-03-22 1800

3. K.P. Jain 30000 36 NULL 2007-03-08 1600

4. M.P. Yadav 80000 60 10.00 2008-12-06 2250

5. S.P. Sinha 20000 36 12.50 2010-01-03 4500

6. P. Sharma 70000 60 12.50 2008-06-05 3500

7. K.S. Dhali 50000 48 NULL 2008-03-05 3800


SQL QUERIES

(I) Display the sum of all Loan Amounts whose interest rate is greater than
10.
Ans: Mysql> SELECT SUM(Loan_Amount) FROM LOANS WHERE Int_Rato>10;

(ii) Display the Maximum Interest from Loans table.


Ans: Mysql> SELECT MAX(Interest) FROM LOANS;

(iii) Display the count of all loan holders whose name ends with 'Sharma’.
Ans: Mysql> SELECT COUNT(*) FROM LOANS WHERE Cust_Name LIKE ‘%Sharma’;

(iv) Display the count of all loan holders whose Interest rate is Null.
Ans: Mysql> SELECT COUNT(*) FROM LOANS WHERE Int_Rate IS NULL;

(v) Display the Interest-wise details of Loan Account Holders.


Ans: Mysql> SELECT * FROM LOANS ORDER BY Interest;
Product table client TABLE

P_ID Product_Nam Manufactur Pric C_ID Client_Name City P_ID


e e e
01 Cosmetic Shop Delhi FW05
TP01 Talcum Powder LAK 40
06 Total Health Mumbai BS01
FW05 Face Wash ABC 45
12 Live Life Delhi SH06
BS01 Bath Soap ABC 55
15 Pretty Woman Delhi FW12
SH06 Shampoo XYZ 120
16 Dreams Bengaluru TP01
FW12 Face Wash XYZ 95
SQL QUERIES

(i)To display the details of those Clients whose city is Delhi.


Ans: SELECT * FROM CLIENT WHERE City = “Delhi”;
(ii)To display the details of Products whose Price is in the range of 50 to
100(both values included).
Ans: SELECT * FROM PRODUCT WHERE PRICE BETWEEN 50 and 100;
(iii)To display the details of those products whose name ends with 'Wash'.
Ans: SELECT * FROM PRODUCT WHERE Product_Name LIKE ‘%Wash';
(iv) To display C_ID. ClientName. City of all the clients(including the ones
that have not purchased a product) and their corresponding Product_Name
sold.
Ans: SELECT C_ID, Client_Name, City, Product_Name FROM Client LEFT JOIN Product
ON Client. P_ID = Product.P_1D;
(v) To display total number of records in the Product table on the basis of
Manufacturer with no duplicate values.
Ans: SELECT COUNT(DISTINCT Manufacturer) FROM Product;
COMPANY table MODEL TABLE

Mode C_ID Cost DateOfManufactu


C_ID CompName CompHO ContactPerso
l_ID re
n
T020 1 2000 2010-05-12
1 Titan Okhla C.B. Ajit
M032 4 7000 2009-04-15
2 Ajanta Najafgarh R. Mehta
M059 2 800 2009-09-23
3 Maxima Shahdara B. Kohli
A167 3 1200 2011-01-12
4 Seiko Okhla R. Chadha
T024 1 1300 2009-10-14
5 Ricoh Shahdara J. Kishore
SQL QUERIES

(i) TO display details Of all models in the Model table in ascending order Of
dateOf Manufacture
Ans: SELECT * FROM Model ORDER BY DATEOfManufacture;
(ii) TO display details Of those models manufactured in 2011 and whose
Cost is below 2000
Ans: SELECT * FROM Model WHERE year(DateOfManufacture)=2011 And Cost<2000;
(iii) To display the Model_ID, C_ID, Cost from the table Model, Compname
and ContactPerson from Company table. with their corresponding comp_lD.
Ans: SELECT Model _ ID, C_ID, Cost, CompName, ContactPerson FROM Model,
Company WHERE MODEL .C_ID = Company.C_ID;
(iv) To decrease the cost of all the models in Model table by 15%.
Ans: UPDATE Model SET Cost = Cost - 0.15*Cost;
(v) To display total number of records in the Company table on the basis of
CompHO with no duplicate values.
Ans: SELECT COUNT(DISTINCT CompHO) FROM Company;
stock table
ItemNo Item Dcode Qty UnitPrice StockDate

5005 Ball Pen 102 100 16 2011-03-31


0.5
5003 Ball Pen 102 150 20 2010-01-01
0.25 Dcode DName
5002 Gel Pen 101 125 14 2010-02-14 101 Reliable Stationers
Premium
5006 Gel Pen 101 200 11 2009-01-09 103 Class Plastics
Classic
104 Fair Deals
5001 Eraser 102 210 4 2009-03-19
Small 102 Clear Deals
5004 Eraser 102 60 10 2010-12-12
Big
5009 Sharpne 103 260 8 2010-01-23
r Classic dealer TABLE
SQL QUERIES

(i) To display details of all models in the Stock table in ascending order of
Stock Date
Ans: SELECT * FROM Stock ORDER BY StockDate;
(ii) TO display details Of those models whose Dealer Code(Dcode) is 102 or
quantity in Stock(Qty) is more than 100.
Ans: SELECT * FROM Stock WHERE Dcode = 102 OR Qty > 100;
(iii) TO insert a record in the Stock table with the values: (5010. 'Pencil HB'.
102. 500. 10. '2010-01-26')
Ans: INSERT INT0 Stock VALUES (5010, 'Pencil HB', 102, 500, 10, '2010-01-26’);
(iv) TO display Dcode, Dname from Dealer table and Item. UnitPrice from
Stock table of all the Dealers (including the dealer details that have not sold
any item)
Ans: SELECT Dealer, Dcode, Item,UnitPrice FROM Dealer LEFT JOIN Stock ON Dealer.
Dcode = Stock. Dcode
(v) TO display the product of Qty & UnitPrice from the table Stock whose
ItemNo is 5006.
Ans: SELECT Qty*UnitPrice FROM Stock WHERE ItemNo=5006;
carden

CCod CarName Make Color Capacity Charges


e
501 A-Star Suzuki Red 3 14

503 Indigo Tata Silver 3 12

502 Innova Toyota White 7 15

509 SX4 Suzuki Silver 4 14

510 C Class Mercedes Red 4 35


SQL QUERIES

(i) To display the names of all the silver-coloured cars.


Ans: SELECT * FROM CARDEN WHERE color = ‘Silver’;
(ii) To display name, make and capacity of cars in descending order of their
sitting capacity.
Ans: SELECT CarName, Make, capacity FROM CARDEN ORDER BY capacity DESC;
(iii) To display the highest charges at which a vehicle can be hired from
CARDEN
Ans: SELECT MAX(Charges) FROM CARDEN;
(iv) To display the names of all the cars whose Capacity is greater than 3.
Ans: SELECT CarName FROM CARDEN WHERE Capacity>3;
(v) To display total number of records on the basis of Make with
no duplicate values.
Ans: SELECT COUNT(DISTINCT Make) FROM CARDEN;
08
INTERFACE PYTHON
SQL CONNECTIVITY
Making SQL SCHOOL
database via python

Source code output


Entering data in SQL
SCHOOL database via
python

Source code output


Deleting data from SQL
SCHOOL database via python

Source code output


Updating data to SQL SCHOOL
database via python

Source code output


“In conclusion, this practical work has been
an enriching experience that has expanded
my understanding of various computer
science concepts and their real-world
applications. It has equipped me with
valuable skills that I can apply in both
academic and professional settings. I have
thoroughly enjoyed the challenges and
opportunities that this course has offered.”

-naki imam

You might also like