Answer to Question #285041 in Python for Vivek

Question #285041

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"


1
Expert's answer
2022-01-05T14:59:00-0500
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}')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS