1 ) Write a function in Python that counts the number of 3) Write a method/function ISTOUPCOUNT() in python to
“Me” or “My” words present in a text file “STORY.TXT”. read contents from a text file WRITER.TXT, to count and
If the “STORY.TXT” contents are as follows: display the occurrence of the word “IS” or “TO” or “UP”.
For example: If the content of the file is
My first book was Me and
My Family. It gave me IT IS UP TO US TO TAKE CARE OF OUR
chance to be Known to the world. SURROUNDING. IT IS NOT POSSIBLE ONLY FOR
The output of the function should be: THE GOVERNMENT TO TAKE RESPONSIBILITY
Count of Me/My in file: 4 The method/function should display
Count of IS TO and UP is 6
2) Write a function AMCount() in Python, which should 4) Write a method/function AEDISP() in python to read
read each character of a text file STORY.TXT, should count lines from a text file WRITER.TXT, and display those lines,
and display the occurance of alphabets A and M . which are starting either with A or starting with E.
Example: For example:
If the file content is as follows: If the content of the file is
Updated information As simplified by official A CLEAN ENVIRONMENT IS NECESSARY FOR OUR GOOD HEALTH.
websites WE SHOULD TAKE CARE OF OUR ENVIRONMENT.
The EUCount() function should display the output as: EDUCATIONAL INSTITUTIONS SHOULD TAKE THE LEAD
A or a:4
M or m :2 The method should display
A CLEAN ENVIRONMENT IS NECESSARY FOR OUR GOOD HEALTH.
EDUCATIONAL INSTITUTIONS SHOULD TAKE THE LEAD.
def AEDISP():
file=open('WRITER.TXT','r')
lines = file.readlines()
for w in lines:
if w[0]=="A" or w[0]=="E":
print (w)
file.close()
5) Write a function in python to count the number of
lines in a text file ‘STORY.TXT’ which is starting with an
alphabet ‘A
6) Write a method/function DISPLAYWORDS() in python 8) Write a user defined function to display the total
to read lines from a text file STORY.TXT, and display those number of words present in the file
words, which are less than 4 characters. A text file “Quotes.Txt” has the following data written in
def DISPLAYWORDS(): it:
Living a life you can be proud of doing your best Spending
c=0 your time with people and activities that are important to
file=open(‘STORY.TXT','r') you Standing up for things that are right even when it’s
line = file.read() hard Becoming the best version of you
word = line.split() The countwords() function should display the output as:
for w in word: Total number of words : 40
if len(w)<4: 9) Write a function COUNT_AND( ) in Python to read the
print(w) text file “STORY.TXT” and count the number of times
“AND” occurs in the file. (include AND/and/And in the
file.close() counting)
7) Write a function in python to count the number lines in 10) Write a function DISPLAYWORDS( ) in python to
a text file ‘Country.txt’ which is starting with an alphabet display the count of words starting with “t” or “T” in a text
‘W’ or ‘H’. file ‘STORY.TXT’.
If the file contents are as follows:
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.
The output of the function should be:
W or w : 1
H or h : 2
def count_W_H():
f = open (“Country.txt”, “r”)
W,H = 0,0
r = f.read()
for x in r:
if x[0] == “W” or x[0] == “w”:
W=W+1
elif x[0] == “H” or x[0] == “h”:
H=H+1
f.close()
print (“W or w :”, W)
print (“H or h :”, H)
11) Write a function that counts and display the number 14) Write a method/function SHOW_TODO() in python to
of 5 letter words in a text file “Sample.txt” read contents from a text file ABC.TXT and display those
lines which have occurrence of the word ‘‘TO’’ or ‘‘DO’’.
12) Write a function to display those lines which start with
the letter “S” from the text file “MyNotes.txt”
15) Write a function in python that displays the number of
lines starting with ‘H’ in the file
13) Write a method/function COUNTLINES_ET() in python 16) Write a Python program to find the number of lines in
to read lines from a text file REPORT.TXT, and COUNT a text file ‘abc.txt’.
those lines which are starting either with ‘E’ and starting
with ‘T’ respectively. And display the Total count f=open("C:\\xii_ip\\abc.txt","r")
separately. linesList=f.readlines()
count=len(linesList)
print(count) f.close()
17) Write a function/method DISPLAY () in
python to read a text file line by line and display
each word separated by '#'
18) Write a function/method
DISPLAYRECORDS() in Python to read a text file
"Story.txt" and displays the number of Vowels/
/Lowercase / Uppercase/characters in the file.
19) Write a function in python to read lines from file
“POEM.txt” and display all those words, which has two
characters in it.
20) 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”.