Write a method in Python to read the text file INDIA.TXT and
count the number of times word “India” occur in the file.
Answers
Answer:
f= open ( india.txt,"r")
t= f.read()
count=0
for I in range ():
if I =='india'
print( count)
The method in Python to browse the computer file INDIA.TXT.
For example if the content of the file is given as follows :
India has simply celebrated its seventy-fiftieth Independence Day on fifteenth August. The day was joyful celebrated everywhere the state and a number of other superpatriotic activities were seen within the entire nation. Bharat encompasses a special place within the world thanks to many reasons that typically asked within the SSB interviews. Bharat has the ordinal largest population and therefore the seventh largest geographical region within the world.
The output ought to be four.
The codes area unit as follows :
def display1(): c=0 file=open('INDIA.TXT','r') c=0 for LINE in file: Words = LINE.split() for W in Words: if W=="India": c=c+1 print c file.close()
The number of times word “India” occur within the file is 2.
#SPJ3