To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
Define a function which will count the word in the given file.
Create a file pointer and open the file.
Initialize word count as zero.
For each line in file, split it into words and find number of the words in every line.
Sum the number of words in each line.
Display the total words in the file.
Close the file pointer and end the program.
Developed by: Antony Abishek K
Register no: 212223240009
num=0
with open("story.txt","r") as f1:
for i in f1:
word=i.split()
num += len(word)
print("The number of words are in the file is ",num)
Thus the program is written to find the word count from a text.