Q. Write a method in python to read lines from a text file INDIA.TXT, to find and display the occurrence of the word "India".
For example:- If the content of the file is
"India is the fastest growing economy.
India is looking for more investments around the globe.
The whole world is looking at India as a great market.
Most of the Indians can foresee the heights that India is
capable of reaching."
The output should be 4
Answer :-
def display1(): count = 0 file = open("INDIA.TXT","r") for LINE in file: Words = LINE.split() for W in Words: if W == "India": count = count + 1 print (count) file.close()
Output :-
>>> display1()
4
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )