XII CS practical (1-17)Session 2024-25
XII CS practical (1-17)Session 2024-25
XII CS practical (1-17)Session 2024-25
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
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
#code continue
4
Page
Output:
5
Page
#function call
7
Page
Output:
8
Page
# 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("Input value:", n)
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
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
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
Output:
13
Page
Output:
16
Page
Practical 6-Write a program to read the file line by line and display each word
separated by #
Solution:
17
Page
Output:
18
Page
Output:
22
Page
Output:
24
Page
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
Output:
26
Page
#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
Output:
28
Page
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
Output:
30
Page
Output:
33
Page
Output:
36
Page
Output:
39
Page
#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
Output:
41
Page
Output:
43
Page
Output:
45
Page