To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
Create a new text file
Add some sentence to the file
Now in the main.py file using split function,split the words in the .txt file
Count the splitted Words
Add the counted number in the variable
Run the program and display the results
program to find the number of words in a text file
Developed by : Easwari M
Register number : 212223240033
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.