Saturday, April 3, 2021

Count Number of Words From a Text File in Python

 In this program I will show you how to count the number of words from a text file using Python programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com




Program Listing


data.txt

Python Programming is Fun and Profit
Professor Jake Rodriguez Pomperada
reading_textfile.py
# reading_textfile.py
# Mr. Jake Rodriguez Pomperada, MAED-IT, MIT
# www.jakerpomperada.com www.jakerpomperada.blogspot.com
# jakerpomperada@gmail.com
# April 3, 2021
# Bacolod City, Negros Occidental

print()
print("\tCount Number of Words From a Text File in Python");
print()
try:
print()
fr = open("data.txt","r")
for line in fr:
line = line.strip("\n")
print(line.upper())
words = line.split()

print()
print('Total number of words: ', len(words))
print("-----------------------------------------------")
print()
print("\tEND OF PROGRAM");
print()
fr.close()
except FileNotFoundError:
print("File is not found")


1 comment:

  1. This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine. word counter tool

    ReplyDelete