ASSIGNMENT – TEXT FILES
1. Write a function countINDIA() which read a text file ‘[Link]’ and print the
frequency of the words ‘India’ in it (ignoring case of the word).
Example: If the file content is as follows:
INDIA is my country. I live in India. India has many states.
The countIndia() function should display the output as:
Frequency of India is 3.
2. Write a function countVowel() in Python, which should read each character of a
text file “[Link]” and then count and display the count of occurrence of vowels
(including small cases and upper case).
3. Write a function COUNT_AND( ) in Python to read the text file “[Link]” and
count the number of times “AND” occurs in the file. (include AND/and/And in the
counting)
4. Write a function DISPLAYWORDS( ) in python to display the count of words
starting with “t” or “T” in a text file ‘[Link]’.Write a method/function
DISPLAYWORDS() in python to read lines from a text file [Link], and
display those words, which are less than 4 characters.
5. Write a function RevText() to read a text file "[Link]" and Print only word starting
with 'I' in reverse order.
Example:
If value in text file is:
INDIA IS MY COUNTRY
Output will be: AIDNI SI MY COUNTRY.
6. Write a method COUNTLINES() in Python to read lines from text file
‘[Link]’ and display the lines which are starting with any article (a,
an, the) insensitive of the case.
Example:
If the file content is as follows:
Give what you want to get.
We all pray for everyone’s safety.
A marked difference will come in our country.
The Prime Minister is doing amazing things.
The COUNTLINES() function should display the output as:
The number of lines starting with any article are : 2
7. Suppose conten tof '[Link]' is:
Humpty Dumpty sat on a wall
Humpty Dumpty had a great fall
All the king's horses and all the king's men
Couldn't put Humpty together again
Write a python function named RECORD to calculate total number of lines in ‘
[Link]’
8. Write a function reverseFile()in Python, which should read the content of a text file
“[Link]” and display all its line in the reverse order.
Example: If the file content is as follows:
It rained yesterday.
It might rain today.
I wish it rains tomorrow too.
I love Rain.
The RainCount()function should display the output as:
.yadretsey deniar tI
.yadot niar thgim tI
.oot worromot sniar ti hsiw I
.niaR evol I
9. A text file “[Link]” contains alphanumeric text. Write a program that reads
this text file and writes to another file “[Link]” entire file except the
numbers or digits in the file.
10. Write a function COUNTLINES( ) which reads a text file [Link] and then
count and display the number of the lines which starts and ends with same letter
irrespective of its case . For example if the content of the text file [Link] is :
The person has a sent a lovely tweet
Boy standing at station is very disturbed
Even when there is no light we can see
How lovely is the situation
The expected output is :
The Number of lines starting with same letter is 2