To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
create a file and add some content to it
open file using with keyboard/built-in function in read mode
use read() to read the contents of the file.
split the lines using split().
iterate the list and increament the count.
print the output
#program to find number of words
#developed by:s.thirisha
#register number: 22001920
fname = input('enter file name: ')
num_words = 0
with open(fname, 'r') as f:
for line in f:
words = line.split()
num_words += len(words)
print('number of words: ',num_words)
Thus the program is written to find the word count from a text.