To write a python program for getting the word count from a file.
PC Anaconda - Python 3.7
Create a txt file to count the number of word in that file.
Open the txt file in read mode using open().
Using split() function to split the words in the txt file and count it.
Save the python program using .py extention.
Run the python program in terminal to get the output.
Number of words in the txt file is displayed as the output.
'''Reference no : 21500608
Developed by : Pavizhi.B'''
num_words =0
with open('name.txt','r') as file1:
for i in file1:
word =i.split()
num_words += len(word)
print("Number of words={0}".format(num_words))
Thus the program is written to find the word count from a file.