Class XII Computer Science – Sample Paper – 2
File Handling – Text Files & CSV Files
Section A
Date: 23/11/2025 Time: 1 Hour Max Marks: 20
1. Write a code to count and display no. of alphabets, digits and spaces separately in
a text file named “[Link]”. (2)
2. Write a code to count and display no. of occurrences of both „a‟ and „e‟ (case
sensitive) in a text file named “[Link]”. (2)
3. Write a code to display no. of occurrences of all the words starting with „T‟ in a
text file named “[Link]”. (Note: The letter „T‟ is not case sensitive.)
For example If the file contents are: (2)
“A tiny mouse woke up a sleeping lion. The Lion was angry, but the Mouse
begged for forgiveness. Later, the Lion was trapped, and the Mouse helped him
escape. This story teaches us that even small friends can help us.”
The code should display the following output(s):
tiny $ The $ the $ the $ the $ This $ that $
No. of words starting with „t‟ or „T‟ = 7
4. A text file “[Link]” is containing the following data: (3)
" Electronics is the science and engineering field that studies the control of
electron flow through a vacuum, gas, or semiconductor to create devices that
manipulate electricity."
Write a function CountWord() to count and display the no. of occurrences of word
“that” (case sensitive) in the above text file. Also, write the statement to call the
function.
The function should display the following Output:
No. of occurrences of word that: 2
5. Write a function CountWordStart() with reference to the following text file
“[Link]” to count and display the number of occurrences of the words
which starts with the letter „s‟ (Case Sensitive). Also displays the words. (3)
“A garment is a single article of clothing like a shirt, dress, or pair of pants.
Materials: They are most often made from textiles, but historically have also been
crafted from animal skins and other materials. Garments are worn for protection
from the elements, for social reasons like modesty, or as a form of personal
expression through fashion.”
The function should display the following output:
Words starting with s : single shirt skins social
No. of words starting with the letter s = 4
6. Write the definition of a function PrintLines(File Name) which takes a File Name
as an argument, display the lines which is not consisting „:‟ in a text file named
[Link]. (3)
For example If the file contents are:
“Cloud Computing:
It refers to the components and sub-components required for cloud computing.
These components typically refer to:
Front end - Fat client, thin client
Back-end platforms - Servers, Storage.
Cloud-based delivery and a network: Internet, Intranet, Inter-cloud.”
The function should display:
It refers to the components and sub-components required for cloud computing.
Front end - Fat client, thin client
Back-end platforms - Servers, Storage.
7. A csv file "[Link]" contains the data of albums released in a music concert.
Each record of the file contains the following data: (5)
● ACode - int (Album Code)
● ATitle - string (Title of the Album)
● Director - string
● Year - int (Released Year)
● Language - string (Album Language)
● Price - float (Album Selling Rate)
For example, a sample record of the file may be:
[12003, “Eagles”, “Don Hanley”, 1976, “English”, 2450 ]
(i) Write a Python function AddAlbums() to add a album record into the CSV
file.
(ii) Write a Python function ViewAlbums() to display the details of albums
with the price is more than Rs. 25,000.
(iii) Write a Python function ShowLanguage() to display the details of albums
which is released in “French” Language.
All the Best