12th Computer Science Practical User Manual 2024 2025
12th Computer Science Practical User Manual 2024 2025
General Instructions:
1. Eighteen Exercises from Python and Seven from MySQL are practiced in the
practical classes.
Total 30 Marks
1
INDEX
Question Page
S.No Program Name
Number Number
6 PG6 Factorial 14
2
Updating Student Data – Binary
13 PG13 28
File
3
PG1- Removing Repeated Elements from a List
Source Code
4
Result:
Thus the program was executed successfully and output is verified.
5
PG2- Dictionary Creation
Source Code
6
Result:
Thus the program was executed successfully and output is verified.
7
PG3 – Reverse & Swapping List
Write a Python Program to accept 5 items into a list and reverse the list. Also
swap the first and last items in the list.
Source Code
8
Result:
Thus the program was executed successfully and output is verified.
9
PG4 – String Palindrome
Source Code
10
Result:
Thus the program was executed successfully and output is verified.
11
PG5 – Check a Value Exists in Dictionary
Source Code
12
Result:
Thus the program was executed successfully and output is verified.
13
PG6 – Factorial
Source Code
14
Result:
Thus the program was executed successfully and output is verified.
15
PG7 – Arithmetic Operations
Source Code
16
Result:
Thus the program was executed successfully and output is verified.
17
PG8 – Copying Prime Numbers to the List
Source Code
18
Result:
Thus the program was executed successfully and output is verified.
19
PG9 – Swapping Odd and Even Position from List
Write a Python function SwitchOver(Val) to swap the even and odd positions of
the values in the list Val.
Note : Assuming that the list has even number of values in it.
For example :If the list Numbers contain
[25,17,19,13,12,15]
After swapping the list content should be displayed as
[17,25,13,19,15,12]
Source Code
20
Result:
Thus the program was executed successfully and output is verified.
21
PG10 – Displaying words separated by # -Text File
Write a Python Program to read a text file line by line and display each word
separated by '#'.
Source Code
22
Result:
Thus the program was executed successfully and output is verified.
23
PG11 – No of Vowels & Consonants – Text File
Write a Python Program to read a text file and display the number of vowels/
consonants/ uppercase/lowercase characters in the file.
Source Code
24
Result:
Thus the program was executed successfully and output is verified.
25
PG12 – Creating Student Data – Binary File
Write a Python Program to get student data (rollno,name,marks) from user and
write onto a binary file. The program should be able to get data from the user
and write onto the file as long as the user wants.
Source Code
26
Result:
Thus the program was executed successfully and output is verified.
27
PG13 –Updating Student Data – Binary File
Write a Python Program to create a binary file with roll number, name & marks,
input a roll number & update the marks.
Source Code
28
Result:
Thus the program was executed successfully and output is verified.
29
PG14 – Add and Count the data – CSV File
Source Code
30
Result:
Thus the program was executed successfully and output is verified.
31
PG15 – Add and Searching data – CSV File
Write a program in Python that defines and calls the following user defined
functions:
(i) COURIER_ADD() : It takes the values from the user and adds the details to a
csv file 'courier.csv'. Each record consists of a list with field elements as cid,
s_name, Source, destination to store Courier ID, Sender name, Source and
destination address respectively.
(ii) COURIER_SEARCH() : Takes the destination as the input and displays all
the courier records going to that destination.
Source Code
32
Result:
Thus the program was executed successfully and output is verified.
33
PG16 – PUSH and POP Operation to Display Names
Source Code
34
Result:
Thus the program was executed successfully and output is verified.
35
PG17 – PUSH and POP Operation to Display ODD Numbers
Write a Python Program that has a list containing 10 integers. You need to help
him create a program with separate user defined functions to perform the
following operations based on this list.
Traverse the content of the list and push the ODD numbers into a stack.
Pop and display the content of the stack.
Source Code
36
Result:
Thus the program was executed successfully and output is verified.
37
PG18 – PUSH and POP Operation to Display dictionary Values
Write a Python Program that has created a dictionary containing top players and
their runs as key value pairs of cricket team. Write a program, with separate
user defined functions to perform the following operations:
Push the keys (name of the players) of the dictionary into a stack, where
the corresponding value (runs) is greater than 49.
Pop and display the content of the stack
Source Code
38
Result:
Thus the program was executed successfully and output is verified.
39
PG19 – CREATE, ALTER, UPDATE Table Using MySQL
40
(3) Create a Column called “Total” with Integer data type
Query: ALTER TABLE Student ADD COLUMN Total INTEGER;
(4) Assign values to the column Total by adding the marks of PTI and PT2
Query: UPDATE Student SET Total = PT1+PT2;
(5) Display the names of the students who got more than 140 marks in total.
Query: SELECT Name FROM Student WHERE Total>140;
Result:
Thus the program was executed successfully and output is verified.
41
PG20 – SELECT, ORDER BY, DELETE Data Using MySQL
(1) Create a Table with the given constraints and Insert the given values to the created
table.
Query: CREATE TABLE Employee (EmpNo INT PRIMARY KEY, EmpName
VARCHAR(30) NOT NULL, Dept VARCHAR(30), Salary INT, Designation
VARCHAR(30));
Result:
Thus the program was executed successfully and output is verified.
43
PG21 – Aggregate Function, Group By Data Using MySQL
Consider the Student Mark sheet as follows:
(1) Create a Table with the given constraints and Insert the given values to the created
table.
Query: CREATE TABLE COMPUTER(PROD_ID VARCHAR(30) PRIMARY KEY,
PROD_NAME VARCHAR(30) NOT NULL, PRICE INT, COMPANY VARCHAR(20),
TYPE VARCHAR (20));
44
INSERT INTO COMPUTER VALUES ('P001','MOUSE',200,'LOGITECH','INPUT'),
('P002','LASER PRINTER',4000,'CANON','OUTPUT'),
('P003','KEYBOARD',500,'LOGITECH','INPUT'),
('P004','JOYSTICK',1000,'IBALL','INPUT'),('P005','SPEAKER',1200,'CREATIVE','OUT
PUT'),('P006','DESKJET PRINTER',4300,'CANON','OUTPUT');
(4) Display the total price of the product each company wise.
Query: SELECT SUM(PRICE),COMPANY FROM COMPUTER GROUP BY
COMPANY;
(5) Display the difference of highest and lowest salary of each company having maximum
price>1000.
Query: SELECT MAX(PRICE)-MIN(PRICE) “DIFFERENCE” FROM COMPUTER
GROUP BY COMPANY HAVING MAX(PRICE)>1000;
45
(6) To delete the attribute Type in Computer Table.
Query: ALTER TABLE COMPUTER DROP COLUMN TYPE;
Result:
Thus the program was executed successfully and output is verified.
46
PG22 – Displaying Data(SELECT) Using Python With MySQL
To write a code in Python to display all the details of the passengers from the
table flight in MySQL database, Travel. The table contains the following
attributes:
F_ code : Flight code (String)
F_name: Name of flight (String)
Source: Departure city of flight (String)
Destination: Destination city of flight (String)
Consider the following to establish connectivity between Python and MySQL:
● Username : root
● Password : airplane
● Host : localhost
Source Code
47
F_code F_Name Source Destination
F101 Indigo Delhi Chennai
F102 Etihad Delhi Bengaluru
F103 Qatar Airways Mumbai Chennai
F104 Kingfisher Delhi Mumbai
F105 Emirates Mumbai Bengaluru
Result:
Thus the program was executed successfully and output is verified.
48
PG23 – Inserting Data Using Python With MySQL
To write a program in Python to insert the following record in the table named
Bank_Account in MySQL database, Bank:
● Accno – integer
● Cname – string
● Atype – string
● Amount – float
Note the following to establish connectivity between Python and MySQL:
● Username – admin
● Password – root
● Host – localhost
The values of fields Accno, Cname, Atype and Amount have to be accepted from
the user.
Source Code
49
Enter your Account Number : 10326584875
Enter your Name : Arunkumar
Enter your Account Type : SB- Type
Enter The Amount : 50000
A tuple has been inserted
Result:
Thus the program was executed successfully and output is verified.
50
PG24 – Deleting Data Using Python With MySQL
Source Code
51
Enter the Candidate Name: Raman
Candidate Raman, is removed from the table Placement
Result:
Thus the program was executed successfully and output is verified.
52
PG25 – Updating Data Using Python With MySQL
Source Code
53
Enter the Item_code: 111
Enter the Quantity : 20
Item_code 111 ,
Item of Quantity have been updated to 20
Result:
Thus the program was executed successfully and output is verified.
54