To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
first take input of the user
using open function to open
use for loop
the length of the split list should be equal to the number of words in the text files
now,print()
end the program
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('Numbr of words: ', num_words)
Thus the program is written to find the word count from a text.