0% found this document useful (0 votes)
174 views46 pages

XII CS Practical (1-17) Session 2024-25

These are the Set of practicals that a student of Class 12 has to study in order to score in practical exam

Uploaded by

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

XII CS Practical (1-17) Session 2024-25

These are the Set of practicals that a student of Class 12 has to study in order to score in practical exam

Uploaded by

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

Class XII Computer Science Practical List for Session 2021-22

Index
Sr. Date of Data of
Name of the Experiment/Activity
No. Experiment Submission
1. Write a function to check prime, calculate factorial 18/04/2024 22/04/2024
and Fibonacci series.
2. Program to perform various operations on the list. 24/04/2024 29/04/2024
3. Program to handle different types of exceptions. 26/07/2024 30/07/2024
4. Program to read a text file and count and display 30/07/2024 01/08/2024
different types of characters in the file.
5. Write a Python program to find smallest word, 01/08/2024 05/08/2024
biggest word words of specific length, count the
occurrence of specific words from a text file.
6. Write a program to read the file line by line and 05/08/2024 09/08/2024
display each word separated by #
7. Write a program to read text file and display and 09/08/2024 13/08/2024
count different lines from text file.
8 Write a program to append, count and display 13/08/2024 16/08/2024
specific records in text file.
9 Write a program to remove all the lines that contain 16/08/2024 19/08/2024
the character 'a' in a file and write that lines into
another file.
10 Write a program to modify contents of the text file 19/08/2024 22/08/2024
and copy contents from one file to another file
based on condition.
1
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

11 Write a program to create a binary file using list and 22/08/2024 24/08/2024
perform search operation on it.
12 Write a program to create a binary file using 24/08/2024 26/08/2024
dictionary and perform read, append and search
operations on it.
13 Write a program to perform update operation on the 26/08/2024 28/08/2024
binary file.
14 Write a program to perform delete operation on the 28/08/2024 30/08/2024
binary file.
15 Write a menu driven program to create csv file and 30/08/2024 03/09/2024
append student records such as roll number, marks,
total and percentage.
16 Write a program to create csv file and perform 03/09/2024 06/09/2024
search operation on csv file using different criteria.
17 Write a program to copy contents containing 06/09/2024 09/09/2024
phonebook of a csv file into another csv file.
2
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 1-Write a function to check prime, calculate factorial


and Fibonacci series.
Solution:
3
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

#code continue
4
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
5
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 2-Program to perform following operations on the list-


1. To find sum and average of the list
2. Double the odd values and half even values of a list
3. Left shift operation on list by given number
4. Right shift operation on list by given number
Solution:
6
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

#function call
7
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
8
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 3- Write a program to handle different types of exceptions.


Solution:
1. Write a Python program to handle a ZeroDivisionError exception when
dividing a number by zero.
Ans. # Define a function named divide_numbers that takes two parameters: x
and y.
def divide_numbers(x, y):
try:
# Attempt to perform the division operation and store the result in the 'result'
variable.
result = x / y
# Print the result of the division.
print("Result:", result)
except ZeroDivisionError:
# Handle the exception if a division by zero is attempted.
print("The division by zero operation is not allowed.")
# Usage
# Define the numerator and denominator values.
numerator = 100
denominator = 0
# Call the divide_numbers function with the provided numerator and denominator.
divide_numbers(numerator, denominator)
2. Write a Python program that prompts the user to input an integer and
raises a ValueError exception if the input is not a valid integer.
Ans. # Define a function named get_integer_input that takes a prompt as a parameter.
def get_integer_input(prompt):
try:
# Attempt to get an integer input from the user and store it in the 'value'
variable.
value = int(input(prompt))
# Return the integer value.
return value
except ValueError:
# Handle the exception if the user's input is not a valid integer.
print("Error: Invalid input, input a valid integer.")

# Usage
# Call the get_integer_input function to get an integer input from the user with the
provided prompt.
n = get_integer_input("Input an integer: ")
9

# Print the input value obtained from the function.


Page

print("Input value:", n)

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

3. Write a Python program that prompts the user to input two numbers and
raises a TypeError exception if the inputs are not numerical.
Ans. # Define a function named get_numeric_input that takes a prompt as a parameter.
def get_numeric_input(prompt):
# Use a while loop to repeatedly prompt the user until a valid numeric input is
provided.
while True:
try:
# Attempt to get a numeric input (float) from the user and store it in the
'value' variable.
value = float(input(prompt))
# Return the numeric value.
return value
except ValueError:
# Handle the exception if the user's input is not a valid number.
print("Error: Invalid input. Please Input a valid number.")

# Usage
# Call the get_numeric_input function to get the first numeric input from the user
with the provided prompt.
n1 = get_numeric_input("Input the first number: ")
# Call the get_numeric_input function to get the second numeric input from the user
with the provided prompt.
n2 = get_numeric_input("Input the second number: ")
# Calculate the product of the two input numbers.
result = n1 * n2
# Print the result, which is the product of the two numbers.
print("Product of the said two numbers:", result)
4. Write a Python program that executes an operation on a list and handles
an IndexError exception if the index is out of range.
Ans. # Define a function named test_index that takes 'data' and 'index' as parameters.
def test_index(data, index):
try:
# Try to access an element at the specified 'index' in the 'data' list and store it in
the 'result' variable.
result = data[index]
# Perform desired operation using the result (in this case, printing it).
print("Result:", result)
except IndexError:
# Handle the exception if the specified 'index' is out of range for the 'data' list.
10

print("Error: Index out of range.")


Page

# Define a list of numbers 'nums'.

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

nums = [1, 2, 3, 4, 5, 6, 7]
# Prompt the user to input an index and store it in the 'index' variable.
index = int(input("Input the index: "))
# Call the test_index function with the 'nums' list and the user-provided 'index'.
test_index(nums, index)
5. Write a Python program that prompts the user to input a number and
handles a KeyboardInterrupt exception if the user cancels the input.
Ans. # Try to execute the following block of code, which may raise exceptions.
# Prompt the user to input a number and attempt to convert it to an integer, storing it
in the 'n' variable.
try:
n = int(input("Input a number: "))
# If the user input is successfully converted to an integer, print the entered number.
print("You entered:", n)
# Handle the KeyboardInterrupt exception, which occurs when the user cancels the
input (typically by pressing Ctrl+C).
except KeyboardInterrupt:
print("Input canceled by the user.")
6. Write a Python program that executes division and handles an
ArithmeticError exception if there is an arithmetic error.
Ans. # Define a function named 'division' that takes 'dividend' and 'divisor' as parameters.
def division(dividend, divisor):
try:
# Try to perform the division operation and store the result in the 'result' variable.
result = dividend / divisor
# Print the result of the division.
print("Result:", result)
except ArithmeticError:
# Handle the exception if an ArithmeticError occurs during the division
operation.
print("Error: Arithmetic error occurred!")
# Usage
# Prompt the user to input the dividend and store it as a floating-point number in the
'dividend' variable.
dividend = float(input("Input the dividend: "))
# Prompt the user to input the divisor and store it as a floating-point number in the
'divisor' variable.
divisor = float(input("Input the divisor: "))
# Call the 'division' function with the provided dividend and divisor.
division(dividend, divisor)
11
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 4-Read a text file and display the number of digits, alphabets,
vowels, consonants, uppercase , lowercase characters, spaces and other
characters in the file.
Solution:
12
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
13
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 5-Write a Python program to find smallest word, biggest word


words of specific length, count the occurrence of specific words from a
text file.
Solution:
14
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


15
Page Class XII Computer Science Practical List for Session 2021-22

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
16
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 6-Write a program to read the file line by line and display each word
separated by #
Solution:
17
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
18
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


19
Page Class XII Computer Science Practical List for Session 2021-22

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Program 7- Write a program to perform following operations on text file


1. Display 1st and last line of file
2. Read the file contents line by line with each word separated by #
3. Count and display lines start with 'O' or 'o'
4. Count and display line end with a
Solution:
20
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


21
Page Class XII Computer Science Practical List for Session 2021-22

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
22
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Program 8- Write a program to append, count and display specific records


in text file.
Solution:
23
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
24
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Program 9- Write a program to remove all the lines that contain the
character 'a' in the file and write that line it to another file.
Solution:
25
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
26
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

#Practical 10- Write a program to modify contents of the file and copy
contents from one file to another file based on condition.
#Solution:
27
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
28
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 11-Write a program to create a binary file with roll number and
name using list. Search for a given roll number and display the name, if
not found display appropriate message.
Solution:
29
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
30
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

#Practical 12-Write a program to create a binary file using dictionary and


perform read, append and search operations on it.
#Solution
31
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


32
Page Class XII Computer Science Practical List for Session 2021-22

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
33
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 13-Write a program to create a binary file with roll number,


name, and marks and update the binary file by input a roll number and
updates the marks.
Solution:
34
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


35
Page Class XII Computer Science Practical List for Session 2021-22

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
36
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 14-Write a program to create a binary file with roll number,


name and mark and delete a particular record.
Solution:
37
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


38
Page Class XII Computer Science Practical List for Session 2021-22

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
39
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

#Practical 15-Write a menu driven program to create csv file and append
student records such as roll number, marks, total and percentage.
Solution:
40
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
41
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Practical 16-Write a program to create csv file and perform search


operation on csv file using different criteria.
Solution:
42
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
43
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

#Practical 17-Write a program to copy contents containing phonebook of


a csv file into another csv file.
Solution:
44
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel


Class XII Computer Science Practical List for Session 2021-22

Output:
45
Page

Prepared by:Shruti Srivastava,PGT(CS), KV ONGC Panvel

You might also like