To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
Get the file name as the input from the user
Open the file using the withopen function
Use for loop and split function function
Find the length using the num_words += len(words)
Print the program
End the progrm
Word count
Name: Soundariyan M N
Register no: 22008347
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.