To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
Step 1: Create a function that prompts user to give a name of a text file to count the number of words in it.
'''
python program for getting the word count from a text.
Developed by: SRIJITH R
RegisterNumber: 21004191
'''
with open("text.txt",'w')as fp:
fp.write("Hello have a good day")
fp.write("\nWelcome to python programming")
fp.write("\nPython Files concept\n")
def wordcount(filen):
count = 0
with open(filen,"r") as f1:
data=f1.read()
for line in data.split():
count += 1
print("The word count is", count)
filename=input("Enter Filename:")
wordcount(filename)
Thus the program is written to find the word count from a text.