Computer Science, asked by manyasri1234, 4 months ago

Write a function in Python to read lines from a text file "notes.txt", to find and display the

occurrence of the word "the".

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 5​

Answers

Answered by Oreki
2

def count(file, word):

from os import path, sys

from collections import Counter

if path.isfile("notes.txt"):

with open("notes.txt", 'r') as notes:

return Counter(notes.read( ).lower( ).split( )).get(word)

else:

print("Some files seem to be missing...")

sys.exit( )

Answered by michaelragea1
0

Answer:

def number_of_words(fname)

with open ('file.txt') as f

count =0

d= f.read

words = d.split()

for x in words :

if x =='the'

count = count +1

print (count)

number_of_words('file.txt')

Similar questions