1.

Write a program to count the words "to"and "the"present in text file"poen.txt"

Answer»

#code

f = open ('Poem, txt','r')

c_to = θ    # count of 'to'

c_the = θ  # count of 'the'

for line in f:

c_to += line.count ('to')     # count ( ) function counts the occurrences of the word 

c_the += line.count ('the')  # 'the' otherwise it would count words like 'soothe'

print (c_to)

print (c_the)



Discussion

No Comment Found