Create a text file with name "article.txt". Write a function in Python to count the number of articles
(words "a", "an", "the") present in a text file "article.txt"
count = 0
with open('article.txt') as f:
for line in f:
for word in line.split():
word = word.lower()
if word == 'a' or word == 'an' or word == 'the':
count += 1
print(f'The total number of articles in "article.xt" is {count}')
Comments
Leave a comment