0% found this document useful (0 votes)
42 views

TEXT FILE HANDLING Questions

The document contains a list of programming questions related to text file handling in Python for Grade 12 Computer Science students. Each question requires the student to write functions that perform various operations on text files, such as counting specific words, displaying lines that start with certain letters, and manipulating file contents. The tasks aim to enhance students' understanding of file operations and string manipulation in Python.

Uploaded by

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

TEXT FILE HANDLING Questions

The document contains a list of programming questions related to text file handling in Python for Grade 12 Computer Science students. Each question requires the student to write functions that perform various operations on text files, such as counting specific words, displaying lines that start with certain letters, and manipulating file contents. The tasks aim to enhance students' understanding of file operations and string manipulation in Python.

Uploaded by

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

SRI AMBAL THULASI PUBLIC SCHOOL SENIOR SECONDARY, ANNUR-641653

Topic: Text File Handling Programming Questions


Class: Grade 12 Subject: Computer Science

1. Write a user defined function in python that displays the number of lines starting with 'H' in
the file para.txt.

2. Write a function countmy() in python to write the text file "DATA.TXT" and count the
number of times "my" occurs in the file. For example if the file DATA.TXT contains-"This is
my website. I have displayed my preference in the CHOICE section ".-the countmy() function
should display the output as:"my occurs 2 times".

3. Write a method in python to read lines from a text file DIARY.TXT and display those lines
which start with the alphabets P.

4. Write a method in python to read lines from a text file MYNOTES.TXT and display those
lines which start with alphabets 'K'.

5. Write a program that copies a text file "source.txt" onto "target.txt" barring the lines starting
with @ sign.

6. Write a function in Python to read a text file, Alpha.txt and displays those lines which begin
with the word ‘You’.

7. Write a function, vowelCount() in Python that counts and displays the number of vowels in the
text file named Poem.txt.

8. Read a text file line by line and display each word separated by a #.

9. Read a text file and display the number of vowels/consonants/uppercase/lowercase characters


in the file.

10. Remove all the lines that contain the character 'a' in a file and write it to another file.

11. Write a function COUNT_AND( ) in Python to read the text file “STORY.TXT” and
count the number of times “AND” occurs in the file. (include AND/and/And in the
counting)

12. Write a function DISPLAYWORDS( ) in python to display the count of words starting
with “t” or “T” in a text file ‘STORY.TXT’.

13. Write a function in python to read lines from file “POEM.txt” and display all
those words, which has two characters in it.
For e.g. if the content of file is
O Corona O Corona
Jaldi se tum Go na
Social Distancing ka palan karona

sabse 1 meter ki duri rakhona


Lockdown me ghar me ho to online padhai karona
O Corona O Corona Jaldi se tum Go na
Output should be : se Go na ka ki me me ho to se Go na

14. Write a function COUNT() in Python to read contents from file “REPEATED.TXT”, to
count and display the occurrence of the word “Catholic” or “mother”.
For example:
If the content of the file is
“Nory was a Catholic because her mother was a Catholic, and Nory‟s mother was a Catholic
because her father was a Catholic, and her father was a Catholic because his mother was a
Catholic , or had been.
The function should display:
Count of Catholic, mother is 9

15. Write a function that counts and display the number of 5 letter words in a
text file “Sample.txt”

16. Write a function to display those lines which start with the letter “S” from
the text file “MyNotes.txt”.

17. Write a method/function COUNTLINES_ET() in python to read lines from a


text file REPORT.TXT, and COUNT those lines which are starting either with
‘E’ and starting with ‘T’ respectively. And display the Total count separately.
For example: if REPORT.TXT consists of
“ENTRY LEVEL OF PROGRAMMING CAN BE LEARNED FROM
PYTHON. ALSO, IT IS VERY FLEXIBLE LANGUGAE. THIS WILL BE
USEFUL FOR VARIETY OF USERS.”
Then, Output will be:
No. of Lines with E: 1
No. of Lines with T: 1

18. Write a method/function SHOW_TODO() in python to read contents from a text


file ABC.TXT and display those lines which have occurrence of the word ‘‘TO’’ or
‘‘DO’’.
For example : If the content of the file is
“THIS IS IMPORTANT TO NOTE THAT SUCCESS IS THE RESULT OF
HARD WORK. WE ALL ARE EXPECTED TO DO HARD WORK. AFTER
ALL EXPERIENCE COMES FROM HARDWORK.”
The method/function should display:
* THIS IS IMPORTANT TO NOTE THAT SUCCESS IS THE RESULT
OF HARD WORK.
* WE ALL ARE EXPECTED TO DO HARD WORK.

19. Write a function in Python that counts the number of “Me” or “My” words present in a text
file
“STORY.TXT”. If the “STORY.TXT” contents are as follows:
My first book was Me and My Family.
It gave me chance to be Known to the world.

The output of the function should be: Count of Me/My in file: 4


20. Write a function AMCount() in Python, which should read each character of a text file
STORY.TXT, should
count and display the occurrences of alphabets A and M (including small cases a and m too).
Example: If the file content is as follows:
Updated information As simplified by official websites.
The AMCount() function should display the output as: A or a: 4 M or m :2

21. Write a function in python that displays the number of lines starting with ‘H’
in the file
“para.txt”. Example, if file contains:
Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow
Then the lines count should be 2

22. Write a function countmy() in Python to read file Data.txt and count the
number of times “my” occur in file. For example, if the file contain
This is my website. I have displayed my preferences in the choice section
The countmy() function should display the output as :” my occurs 2 times”

23. Write a Python program to find the number of lines in a text file ‘abc.txt’.

24. Write a Python program to count the word “if “ in a text file abc.txt’.

25. Write a function in Python that counts the number of “Me” or “My” words 3
present in a text file “STORY.TXT”.
If the “STORY.TXT” contents are as follows:
My first book was Me and My Family. It gave me chance to be Known to the world.
The output of the function should be:
Count of Me/My in file: 4

26. Write a function AMCount() in Python, which should read each


character of a text file STORY.TXT, should count and display the
occurance of alphabets A and M (including small cases a and m too).
Example:
If the file content is as follows:
Updated information
As simplified by official websites.
The EUCount() function should display the output as:
A or a:4
M or m :2

27. Write a method in python to read lines from a text file DIARY.TXT and display
those lines which start with the alphabets P.

28. Write a function countmy( ) in python to read the text file "mystory.txt" and count
the number of times "my" occurs in the file. For example if the file mystory.txt
contains:
"This is my school. I love to play and study in my school."
the countmy( ) function should display the output as:"my occurs 2 times".
29. Write a method/function ISTOUPCOUNT() in python to read contents from a text file
WRITER.TXT, to count and display the occurrence of the word ‘‘IS’’ or ‘‘TO’’ or ‘‘UP’’.
For example : If the content of the file is-
IT IS UP TO US TO TAKE CARE OF OUR SURROUNDING. IT IS NOT POSSIBLE
ONLY FOR THE GOVERNMENT TO TAKE RESPONSIBILITY
The method/function should display Count of IS TO and UP is 6

30. Write a function AMCount() in Python, which should read each character of a text
file STORY.TXT, should count and display the occurrence of alphabets A and M
(including small cases a and m too).
Example:
If the file content is as follows:
Updated information
As simplified by official websites.
The AMCount() function should display the output as:
A or a:4

31. Write a function in Python that counts the number of “The” or “This”
words present in a text file “MY_TEXT_FILE.TXT”.
Note: (The comparison should be case insensitive)

32. Write a function VowelCount() in Python, which should read each


character of a text file MY_TEXT_FILE.TXT, should count and display
the occurrence of alphabets vowels.
Example:
If the file content is as follows:
Updated information
As simplified by official websites.
The VowelCount() function should display the output as:
A or a:4
E or e :4
I or I :8
O or o : 0
U or u: 1

33. Write a function count_Dwords() in python to count the words ending with a digit in a text
file “Details.txt”.
Example: If the file content is as follows:
On seat2 VIP1 will sit and
On seat1 VVIP2 will be sitting
Output will be:
Number of words ending with a digit are 4

You might also like