XII practical format 2024-25 (1)
XII practical format 2024-25 (1)
Practical Record
2024-25
PRACTICAL – 01
PRACTICAL – 02
Aim of the practical –
Remove all the lines that contain the character 'a' in a file and
write it to another file.
Conditional Statements and Loops Used –
1. for loop
2. if-else statement
Functions Used –
1. open() function
2. close() function
3. write() function
Procedure Followed –
The user will be asked to open a text file in ‘r’ mode and another in ‘w’ mode. Then the
user will read the entire file using the read function and store it in a variable.
Then by using a for loop, it will get to each line of the file and check whether the line is
beginning with ‘a’ using if-else statement.
Then the lines which are not beginning with a will be written in
the other fil
e opened in ‘w’ mode using the write function.
Coding –
Output –
Paste the picture of the o/p.
And
Paste the picture of the file
which is being read.
PRACTICAL - 03
Aim of the practical –
Create a binary file with name and roll number. Search for a
given roll number and display the name, if not found display
appropriate message.
Conditional Statements and Loops Used –
1. for loop
2. if-else statement
Functions Used –
1. open() function
2. close() function
3. dump() function
4. load() function
Modules Used –
1. Pickle module
Procedure Followed –
Procedure-1 (creating the file)
1. First the user needs to import the pickle module.
2. Then need to open a binary file in ‘wb+’ mode.
3. Then the user needs to tell the number of data he wants to store.
4. Then using a for loop, need to run the program that many times and simultaneously
take the input (name, roll no.) from the user and write it in the binary file using the dump
function.
Procedure-2 (Searching for a given roll no.)
1. Then the user needs to read the binary file using load function and store it in a variable.
2. Then the user needs to input the roll no. whose name he wants to see after that using
the for loop, we need to access each name roll no. pair, then we need to compare the roll
no. using if-else statement where the roll no. matches, we need to display the
corresponding name.
3. If the roll no. is not found then we need to display the appropriate message.
Coding –
Output -
Paste the picture of the o/p.
And
Paste the picture of the file
which is being read.
PRACTICAL - 04
Aim of the practical –
Create a binary file with roll number, name and marks. Input a roll number and update
the marks.
Conditional Statements and Loops Used –
1. for loop
2. if-else statement
Functions Used –
1. open() function
2. close() function
3. dump() function
4. load() function
Modules Used –
1. Pickle module
Procedure Followed –
Procedure-1 (creating the file)
1. First the user needs to import the pickle module.
2. Then need to open a binary file in ‘wb+’ mode.
3. Then the user needs to tell the number of data he wants to store.
4. Then using a for loop, need to run the program that many times and simultaneously
take the input (name, roll no., marks) from the user and write it in the binary file using
the dump function.
Procedure-2
(Searching for a given roll no. and updating the marks)
1. Then the user needs to read the binary file using load function and store it in a variable.
2. Then the user needs to input the roll no. whose mark he want to update after that using
the for loop, we need to access each (name, roll no., mark set), then we need to compare
the roll no. using if-else statement where the roll no. matches, we need to update the mark
of that student.
3. If the roll no. is not found then we need to display the appropriate message.
Coding –
Output -
Paste the picture of the o/p.
And
Paste the picture of the file
which is being read.
PRACTICAL - 05
Aim of the practical –
Write a random number generator that generates random
numbers between 1 and 6 (simulates a dice).
Modules Used –
1. Random module
Functions Used –
1. randint() function
Procedure Followed –
1. First the user needs to import the random module.
2. Then using the randint() function need to set values b/w which numbers he want to
generate random numbers and store it in a variable and print it.
Coding –
Output -
Paste the picture of the o/p.
PRACTICAL - 06
Aim of the practical –
Write a Python program to implement a stack(push and pop) using list.
Conditional Statements and Loops Used –
1. if-else statement
2. while loop
3. for loop
Functions Used –
1. append() function
2. pop() function
Procedure Followed –
Procedure-1 (Inserting element in stack)
1. Using the while loop we need to continuously take input from the user till he wants and
simultaneously append it into the list.
2. When he wants to stop, we need and break the loop and display the stack.
3. If the stack becomes full the display appropriate message and stop taking input.
Procedure-2 (Deleting element from stack)
1. First the user needs to input how many elements he wants to remove from the stack.
2. Then we need to reverse the stack because the element which is inserted at last will
become the first element to be popped out.
3. Then using the for loop, we run the loop that many times as input is given by the user
and need to pop the same number of elements from the stack/list.
4. If the list/stack becomes empty display appropriate message.
Coding –
Output -
Paste the picture of the output.
PRACTICAL - 07
Aim of the practical –
Create a CSV file by entering user-id and password, read and
search the password for given user-id.
Conditional Statements and Loops Used –
1. for loop
2. if-else statement
Modules Used –
1. CSV Module
Procedure Followed –
Procedure-1 (creating the file)
1. First the user needs to import the csv module.
2. Then need to open a csv file in ‘w+’ mode.
3. Then the user needs to create a writer object to write in the csv file.
4. Then the user needs to tell the number of data he wants to store.
5. Then using a for loop, need to run the program that many times and simultaneously
take the input (user-id and password) from the user and write it in the csv file using
the writer object.
Procedure-2 (Searching the password using the user-id)
1. First the user needs to create a reader object.
2. Then the user needs to read the csv file using the reader object and store it in a
variable.
3. Then the user needs to input the user-id whose password he want to get after that using
the for loop, we need to access each (user-id and password pair), then we need to
compare the user-id using if-else statement where the user-id matches, we need to display
that user’s password.
4. If the user-id is not found then we need to display the appropriate message
Coding –
Output -
Paste the picture of the o/p.
And
Paste the picture of the file
which is being read.
PRACTICAL - 08
Aim of the practical –
Read a text file line by line and display each word separated by a #.
Conditional Statements and Loops Used –
1. for loop
Functions Used –
1. open() function
2. close() function
3. join() function
4. split() function
Procedure Followed –
1. The user needs to open a text file in ‘r’ mode.
2. Then user need to read the file and store it in a variable.
3. Then using for loop get access to each line of the file.
4. Using the split function, need to separate each word and store it in the form of a list.
5. Then using the join function, we need the join each word using ‘#’ and display it.
Coding –
Output -
Paste the picture of the output.
And
Paste the picture of the file
which is being read.
PRACTICAL - 09
Aim of the practical –
Write program to increase the salary by 2000/- of the employee having empno as 1251 in
the file emp.dat.
module used:
import pickle
Exception used:
try: …….. except EOFError:
function used:
open(), close(), seek(), tell(), print(), dump(), load()
Procedure used:
1. Open the file in rb+ mode, move to starting position.
2. Inside try: run while loop , inside which load all the record data.
3. Then check for empno. 1251, if true then change the data, then dump it in that
particular position.
4. Then print the employee record.
5. In except check if record not found error message, is found successful message.
Then close the file.
Coding:
OUTPUT
PRACTICAL - 10
Aim of the practical –
Write a program to read following details of sports performance (sport, competitions, prize won) of your
school and store into a csv file delimited with tab character.
module used:
import CSV
function used:
reader(), print(), input(), mention if any more
Procedure used:
Coding:
OUTPUT
PRACTICAL - 11
Aim of the practical –
Write a program to read following details of sports performance (sport, competitions,
prize-won) of your school and store into a CSV file delimited with tab character.
function used:
open(), close(), writer(), writerow(), print(), int(), input()
module used:
import csv
Procedure used:
1. Import the CSV file , then open the file in write mode.
2. In writer() use argument file & delimiter = ‘\t’
3. Write the headings then start the loop to input individual record then write as row
4. Lastly close the file
Code:
Output:
PRACTICAL - 12
Aim of the practical –
Write a function stats() that accepts a filename and reports the file’s longest line
function used:
module used:
Procedure used:
Code:
Output:
PRACTICAL - 13
Aim of the practical –
A binary file “book.dat” has a structure [BookNo, Book_Name, Author, Price].
i) Write a user defined function createfile() to input data for a record and add to
book.dat.
ii) Write a function countRec(Author) in Python which accepts the Author as
parameter and count and return number of books by the given Author are
stored in the binary file “book.dat”
function used:
open(), close(), dump(), load(), print(), int(), input()
module used:
import pickle
Conditions & loops used:
while loop
if….
Exception used:
try: …….. except
Procedure used:
Part-1
1. Import then open the file in append mode.
2. Insert data according to the structure, then dump it
Part-2
Code:
Output:
PRACTICAL - 14
Aim of the practical –
To print the cube of numbers in range 15 to 20
function used:
module used:
Procedure used:
Code:
Output:
PRACTICAL - 15
Aim of the practical –
Program to print square of every alternate number in range (1,5,2).
function used:
module used:
Procedure used:
Code:
PRACTICAL - 16
Aim of the practical –
Write a program that multiplies two integers without using * operator (by using repeated
addition).
function used:
module used:
Procedure used:
Code:
Output:
Database Practical:
Practical no. 17, 18, 19, 20:
CREATE table with following attributes: RollNo, Name, Class, DOB, Gender, City,
Total_Marks(out of 300)
ALTER table to add new attribute as percentage (= (Total_Marks/300) *100) or
modify datatype or DROP any attribute
UPDATE table to modify any data
ORDER BY to display data in ascending and then descending order
DELETE to remove any column data or row
GROUP BY and find MIN(), MAX(), SUM(), COUNT() & AVG().
** All the highlighted words in the above statements are the commands to be used
for writing the SQL queries in MySql.
** Display the table After each query is executed. (Display / Describe) except Order
by & group by as directly their output has to be printed.
a. DROP column name Gender from Students table using ALTER command.
b. INSERT a record
c. DISPLAY the record of students who have secured percentage > 75
d. UPDATE the phnNo of student having PhnNo = ************.