1.

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 andMy 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

Answer»

def displayMeMy(): 

num=0 

f=open("story.txt","rt") 

N=f.read() 

M=N.split() 

for x in M: 

if x=="Me" 

or x== "My": 

print(x) num=num+1 

f.close() 

print("Count of Me/My in file:",num)



Discussion

No Comment Found

Related InterviewSolutions