To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
To write a python program for getting the word count from a text file.
Open the required file by using the function "with"
Then use the laptop to assign the i value in the file
Using split function to spilt the words
Finding the given length of the words by using len() fuction.
Calling the function and Printing the number of words.
#Developed By: BALAMURUGAN B
#Register No: 212222230016
n=input('Enter File name: ')
wordslen=0
with open(n,'r') as f:
for line in f:
words=line.split()
wordslen+=len(words)
print("Number of wordds:",wordslen)
Thus the program is written to find the word count from a text.