Xii Cs - 2024-25 - Practical File
Xii Cs - 2024-25 - Practical File
SCHOOL …………………………………………………………………………………………………………
Name: Batch:
Class: Regd No:
Certificate
Record Total
Teacher - in – charge
SET 1 60
SET 2 63
SET 3 64
SET 4 65
SET 5 68
Program – 1 - A
Program – 1 - B
1
EX.NO.01 User Defined Functions to Manipulate Strings
Separate URL and Replace String
AIM:
B)
RESULT: Thus the python program with user defined functions to perform the above
mentioned tasks in the String was successfully completed and executed successfully.
2
Program – 2 - A
Program – 2 - B
3
EX.NO.02 User Defined Functions to Manipulate Strings
Accept String with All Vowels & Display Common words from 2strings
AIM:
A) To write a function VowelStr(data) in python, that accepts a string as argument and to
display “Input Data is accepted” if the string contains all the vowels. If not, display
“Input Data not accepted”.
B) To write a function COMMON(S1,S2) in python to accept 2 strings as arguments and
to find the common words in both the strings.
SOURCE CODE:
A)
B)
RESULT: Thus the python program with user defined functions to perform the above
mentioned tasks in the String was successfully completed and executed successfully.
4
Program – 3 - A
Program – 3 - B
5
EX.NO: 03 User Defined Functions to manipulate List
Store Indices of Non Zero elements &Double the Odd values
AIM:
A) To write a function INDEX_LIST(L) in python, where L is the list of elements passed
as argument to thefunction. The function returns another list named ‘IndexList’ that stores
the indices of all Non-Zero Elements of L.
For example: If L contains [12,4,0,11,0,56]. The IndexList will have-[0,1,3,5]
B) To write a function DoubletheOdd( ) in python to add and display double the sum of
odd values from the list Nums.
For example : If the Nums contains [25,24,35,20,32,41] .
The function should display Double of Odd Sum: 202
SOURCE CODE:
A)
B)
RESULT: Thus the python program with user defined functions to perform the above
mentioned tasks in the List was successfully completed and executed successfully.
6
Program – 4 - A
Program – 4 - B
7
EX.NO: 04 User Defined Functions to manipulate List
Store Indices of 4 lettered words &Swap adjacent elements
AIM:
A) To write a function lenFOURword(L) in python , where L is the list of elements
(list of words) passed as an argument to the function. The function returns another list
named ‘indexList’ that stores the indices of all four lettered word of L.
B) To write a function SwapAdjacent(nums) in python, that accepts a list as
argument and interchanges the adjacent elements and prints both the original list and
the modified list.
SOURCE CODE:
A)
B)
RESULT : Thus the python program with user defined functions to perform the
above mentioned tasks in the List was successfully completed and executed
successfully.
8
Program – 5 - A
Program – 5 - B
9
EX.NO:05 User Defined Functions to Manipulate List
Find the Longest Word and Shifting the elements to left
AIM:
A) To write a function Longest_Word(Words_list)in python that accepts a list of words as an
argument and returns the longest word from the list with its length.
B) To write a function Lshift(L,N) in python, where L is the list of elements passed as an
argument to the function. The function shifts all the elements by N places to the left and
then print it.For example: If L contains [9,4,0,3,11,56] and N=2
The function will print - [0,3,11,56,9,4]
SOURCE CODE:
A)
B)
RESULT : Thus the python program with user defined functions to perform the above
mentioned tasks in the List was successfully completed and executed successfully.
10
Program – 6
11
EX.NO:06 “Guess the Number Game” using random module
AIM:
To write a python program to implement
“Guess the NumberGame” using random module.
SOURCE CODE:
RESULT :Thus the python program to implement “Guess the number game” using random
module was executed successfully.
12
Program – 7.1
Program – 7.2
13
EX.NO.07 Sorting List Of Tuples By Second Item &
Manipulate Student Marks In Nested Tuples
AIM:
A) To write a function Sort_Tuple(tup) in python to sort a list of tuples by the second
item.
B) To write a program to create a nested tuple to store student marks and a function
calc(m) to display the total and average of their marks.
SOURCE CODE:
A)
B)
SOURCE CODE:
A)
RESULT: Thus a python program with user defined functions to manipulate the marks
in nested tuples and sort the elements in tuples has been completed and executed
successfully.
14
Program – 8
15
EX.NO.08 Manipulating Dictionary using Functions
AIM: To write a menu driven python program with user defined functions to manipulate
customer details in a dictionary using function.
SOURCE CODE:
RESULT : Thus the menu driven python program with user defined functions to manipulate
the customer details dictionary has been completed and executed successfully.
16
Program – 9
Content of the file TestFile.TXT
Program – 9.1
Program – 9.2
17
EX.NO.09 TEXT FILES IN PYTHON
Count the occurrences of word & Count number of vowels and consonants
AIM:
A) To write a function RainCount() in Python, which should read the content of a text
file ‘TESTFILE.TXT’ and then count and display the count of occurrence of word
RAIN (case-insensitive) in the file.
B) To write a function Vowels() in Python, which should read the content of a text
file ‘TESTFILE.TXT’ and then count and display the number of vowels and
consonants present in the file.
SOURCE CODE:
A)
B)
RESULT : Thus a Python program to read a text file and to count and display the number of
occurrences of a word and number of vowels and consonants in the file has been completed
and executed successfully.
18
Program – 10
Program – 10.1
Program – 10.2
19
EX.NO.10 TEXT FILES IN PYTHON
Count the lines starts with A/B & Display the lines with exactly 6 words
AIM:
A) To write a function Countlines() in Python to read a text file ‘Poem.txt’ and count and
display the number of lines starts with ‘A’ / ‘B’ separately.
B) To write a function ShowLines() in Python, that would read the contents of a text file
‘Poem.txt’ and display only those lines which contains exactly 6 words in it.
SOURCE CODE:
A)
B)
RESULT : Thus a Python program to read a text file and to count the number of lines starts
with A/B and display the lines contain 6 words has been completed and executed
successfully.
20
Program – 11
Program – 11.1
Program – 11.2
21
EX.NO.11 TEXT FILES IN PYTHON
Copying lines to a new file & Replacing the ‘-‘ sign with a blankspace
AIM:
A) Write a function Filter(oldfile,newfile) in Python that would read the contents of the file
‘source.txt’ and copy only those lines which does not contain ‘@’ sign in it to a new text file
‘target.txt’.
B) Write a function Replace() in Python to read the text file ‘Source.txt’ and to replace the ‘-‘ sign
with blankspace in all the occurrences.
SOURCE CODE:
A)
B)
RESULT : Thus a Python program to read a text file and to copy the lines to a new file and
replacing ‘’ sign with a blankspace has been completed and executed successfully.
22
Program – 12 .1
23
EX.NO.12 TEXT FILES IN PYTHON
Remove duplicate lines from the file & Display unique words present in the file
AIM:
A) Write a function RemoveLines() in Python that would read the contents of the file ‘Poem.txt’
and remove the duplicate lines from the file.
B) Write a function UniqueWord() in Python to read the text file ‘Stars.txt’ and to display the
unique words from the file.
SOURCE CODE:
A)
B)
RESULT : Thus a Python program to read a text file and to remove the duplicate lines from
the file and to display the unique words stored in the filehas been completed and executed
successfully.
24
Program – 12.2
25
26
Program – 13
27
EX.NO:13 WORKING WITH BINARY FILE IN PYTHON
Create a binary file, Search and display the records from the binary file
AIM:
(i) To write a user defined function CreateFile() to input the records and add to the binary file
‘Books.dat’ which has the structure [Book_ID, Book_Name, Author, Price].
(ii) To write a function CountRec(Author) which accepts the Author name as parameter and display
the book names and return number of books by the given Author stored in the binary file
‘Books.dat’.
SOURCE CODE:
RESULT:
Thus the user defined functions to create a binary file ‘Books.dat’ and to search and display the book
names number of books by the given Author has been developed in Python and executed
successfully.
28
29
30
Program – 14
31
EX.NO:14 WORKING WITH BINARY FILE IN PYTHON
Create a binary file, Update and display the records from the binary file
AIM:
(i) To write a user defined function AddData() to input and add the records to the binary file
‘Employee.dat’ which has the structure { ‘EmpCode’: , ‘EmpName’: ,
‘Designation’: ,’Salary’: }.
(ii) To write a function UpdateRec(Desgn) which accepts the designation as parameter and update the
salary for the employees with the given designation in the file ‘Employee.dat’. Also display the
records from the file.
SOURCE CODE:
32
33
34
Program – 15
35
36
37
RESULT:
Thus the menu driven python program with separate user defined functions to add records to a binary
file ‘Products.dat’ and to delete and display the records in the file has been developed in Python and
executed successfully.
38
Program - 16
39
EX.NO:16 WORKING WITH CSV FILE IN PYTHON
Create a CSV file, Search and display the records from the CSV file
AIM:
(i) To write a user defined function Create() to input and add the records to the csv file ‘Students.csv’
which has the structure [RollNo, Name, Marks].
(ii) To write a user defined function SearchRec(code) which reads and displays the student records
who have secured above 80 from the file ‘Students.csv’. Also display the number of student records
scored above 80 from the file.
SOURCE CODE:
RESULT:
Thus the user defined functions to add records to a csv file ‘Students.csv’ and to search and display
the records in the file has been developed in Python and executed successfully.
40
Program - 17
41
EX.NO:17 WORKING WITH CSV FILE IN PYTHON
Create a CSV file, Update and display the records from the CSV file
AIM:
To write a Menu driven Python program to implement the following user defined functions.
(i) Create() to input and add the records to the csv file ‘Customers.csv’ which has the structure
[Cust_ID,Cust_Name,City, Contact_No]
(ii) UpdateRec(code) to update the contact number of the customer for the code given by the user
(iii) Display the records stored in the file Customers.csv
SOURCE CODE:
42
43
RESULT:
Thus the menu driven python program with separate user defined functions to add records to a csv file
‘Customers.csv’ and to update and display the records in the file has been developed in Python and
executed successfully.
44
45
46
Program 18
47
EX.NO:18 IMPLEMENTATION OF STACK USING LIST IN PYTHON
AIM:
Consider a dictionary containing non fiction book names and their ratings as key value pairs
as below.
Books={"Behind the beautiful forevers":8.5,"Omnivore's Dilemma":7,"Unnatural
Selection":6.5,"Guns, Germs and Steel":9,"Business Adventures":7.5,"The power of Full
engagement":9.5}
To write a python program with separate user defined functions to perform the following
operations.
(i) Push the keys (Book name) of the dictionary into the stack, where the corresponding value
(rating) is more than 8.
(ii) Pop and display the content of the stack.
Source Code:
48
49
RESULT:
Thus the python program with separate user defined functions to implement the stack using list has
been developed in Python and executed successfully.
50
PROGRAM – 19
51
Ex. No: 19 INTERFACING PYTHON WITH MYSQL
DATABASE CONNECTIVITY APPLICATION PROGRAM - INSERT RECORDS
AIM To write a database connectivity program in Python to establish connection to a MySQL database
‘SCHOOL’ and to do the following.
i) Create a table ‘student’ with the following fields
Rollno-integer(10), primary key, Name varchar(30) not null, Class char(3), Marks decimal(10,2)
ii) To insert the records into the table ‘student’
iii) To retrieve and display all the records stored into the table ‘student’
SOURCE
CODE
RESULT Thus a database connectivity program to create a table, to insert and display the records from the
table student has been created in Python and executed successfully.
52
Program - 19 Cont…
53
54
Program - 20
55
Ex. No: 20 INTERFACING PYTHON WITH MYSQL
DATABASE CONNECTIVITY APPLICATION PROGRAM - UPDATE RECORDS
AIM: To write a database connectivity program in Python to establish connection to a MySQL database
‘SCHOOL’ and to do the following.
i) To update the records into the table ‘student’ for the given rollno
ii) To retrieve and display all the records stored into the table ‘student’
SOURCE
CODE:
RESULT Thus a database connectivity program to update and display the records from the table student has
been created in Python and executed successfully.
56
Program 21
57
Ex. No: 21 INTERFACING PYTHON WITH MYSQL
DATABASE CONNECTIVITY APPLICATION PROGRAM - DELETE RECORDS
AIM: To write a database connectivity program in Python to establish connection to a MySQL database
‘SCHOOL’ and to do the following.
i) To delete the records from the table ‘Student’ for the given rollno
ii) To retrieve and display all the records who have secured marks in the range of 80 to 100 from
the table ‘Student’
SOURCE
CODE:
RESULT Thus a database connectivity program to delete and display the records from the table student has
been created in Python and executed successfully.
58
MySQL Tables
TABLE: OPD
TABLE: WORKER
TABLE: DEPT
59
EX.NO. 22 SQL
SET - 1
Write the SQL Commands for the following questions based on the table OPD.
1) Insert a record into the table OPD using the following data.
REGNO – R0122, NAME – Jilesha, AGE – 32, DEPARTMENT – Cardiology, CHARGES – 700,
GENDER - F (DATEOFREG is unknown)
INSERT INTO OPD (REGNO, NAME, AGE, DEPARTMENT, CHARGES, GENDER)
VALUES (‘R0122’, ‘Jilesha’, 32, ‘Cardiology’, 700, ‘F’)
2) Add a column EXPERIENCE with datatype integer(10) and NOT NULL constraint.
ALTER TABLE OPD ADD COLUMN EXPERIENCE integer(10) NOT NULL;
3) Display the records of the ENT department from table OPD in alphabetical order as per the name of
the doctors.
SELECT * FROM OPD WHERE DEPARTMENT= ‘ENT’ ORDER BY NAME;
4) Display the Name, Department and charges whose charges are in the range of 500 to 1000.
SELECT NAME, DEPARTMENT, CHARGES FROM OPD
WHERE CHARGES BETWEEN 500 and 1000;
SET - 2
Write the SQL Commands for the following questions based on the table OPD.
1) Display REGNO, NAME, DEPARTMENT from the table OPD whose DATEOFREG is not known.
SELECT REGNO, NAME, DEPARTMENT FROM OPD
WHERE DATEOFREG IS NULL;
2) Display the records from the table OPD whose name starts with ‘A’ and contains ‘n’ in it.
SELECT * FROM OPD WHERE NAME LIKE ‘A%n%’;
3) Display the unique values of the DEPARTMENT column of the table OPD.
SELECT DISTINCT DEPARTMENT FROM OPD;
Write the output for the following SQL Commands based on the table OPD.
GENDER COUNT(*)
M 4
F 3
60
TABLE: LAB
TABLE: COMPUTER
TABLE: SALES
P0002 4 1
P0003 2 2
P0001 3 2
P0004 5 1
61
5) SELECT DEPARTMENT, MAX(CHARGES) AS ‘Highest Charge’ FROM OPD
HAVING COUNT(*)>1;
ENT 600
ORTHOPAEDIC 400
CARDIOLOGY 800
SET – 3
Write the output for the following SQL Queries based on the relations WORKER and DEPARTMENT.
COUNT(DISTINCT DCODE)
D01 147000
D05 128000
62
TABLE: PRODUCT
TABLE: CLIENT
63
4) SELECT WNO, WNAME, DEPARTMENT FROM WORKER W
RIGHT JOIN DEPARTMENT D ON W.DCODE = D.DCODE;
MIN(PAY)
62000
MALE 70333.33
FEMALE 69000.00
SET - 4
Write the SQL commands for the following based on the table LAB.
1) Increase the capacity of all the labs by 10 students which are on the I floor.
UPDATE LAB SET CAPACITY = CAPACITY + 10
WHERE FLOOR = ‘I’;
64
65
Write the outputs of the SQL Queries 4 to 7 based on the relations COMPUTER and SALES.
MIN(PRICE) MAX(PRICE)
200 4300
COMPANY SUM(PRICE)
LOGITECH 700
CANON 8300
PROD_NAME QTY_SOLD
MOUSE 3
KEYBOARD 2
JOYSTICK 5
66
67
SET - 5
Write the SQL commands for the following questions based on the tables PRODUCT and CLIENT.
2) To display Product name, manufacturer and price for all the products that are giving discount.
SELECT PNAME, MANUFACTURER, PRICE FROM PRODUCT
WHERE DISCOUNT IS NOT NULL;
3) To display Product name and price for all the products whose name does not end with ‘Wash’.
SELECT PNAME, PRICE FROM PRODUCT
WHERE PNAME NOT LIKE ‘%Wash’;
4) To display the P_ID, Product name and Client name for all the clients whose city is Delhi.
SELECT P. P_ID, PNAME, CNAME FROM PRODUCT P, CLIENT C
WHERE P. P_ID = C. P_ID and C. CITY = ‘Delhi’;
Write the output for the following SQL Queries based on the tables given PRODUCT and CLIENT.
5) SELECT P_ID, PNAME, CNAME, CITY FROM PRODUCT P LEFT JOIN CLIENT C
ON P. P_ID = C. P_ID ;
PNAME COUNT(*)
Bath Soap 1
Face Wash 2
Shampoo 1
Talcum Powder 2
68
69
7) SELECT PNAME, MIN(PRICE) AS “LOWEST PRICE” FROM PRODUCT
GROUP BY PNAME HAVING COUNT(*)>1;
Talcum Powder 40
Face Wash 45
CITY
Delhi
Mumbai
Bengaluru
COUNT(DISCOUNT)
10) SELECT P_ID, PNAME, CNAME, CITY FROM PRODUCT P RIGHT JOIN CLIENT C
ON P. P_ID = C. P_ID ;
70