To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
Open the file in read mode and handle it in test mood.
Read the text using read() function.
Split the text using space separator.We assume that words in a sentance are separted by a space character.
Split the text using space separator.We assume that words in a sentance are separted by a space character.
You can refine the count by cleaning the string prior to splitting or validating the words after splitting.
End the program.
Developed by : ESHWAR T
Register No: 212223230054
def wordcount(filename):
count=0
with open("Myfile.txt","r") as f:
for data in f:
words=data.split()
for word in words:
count+=1
print("Total number of words:",count)
filename=input("Enter Filename:")
wordcount(filename)
Thus the program is written to find the word count from a text.