To write a python program for getting the word count from a text.
PC Anaconda - Python 3.7
Create a file with .txt file extension.
Add some texts in that file.
Create a python file.
Write a code to count the number of words in that file.
Run the program.
Display the output.
def program():
count=0
with open("text.txt","r") as f:
for data in f:
words=data.split()
for word in words:
count+=1
print("Total number of words:",count)
program()
Thus the program is written to find the word count from a text.