Write a python function to count the number of Words in a Text File


Topic: Write a python function to count the number of Words in a Text File

Solution

def check_words():
    fname = input("file name: ")
    num_words = 0
    with open(fname, 'r') as f:
        for line in f:
            words = line.split()
            num_words += len(words)
    print("Number of words = ", num_words)



List all Python Programs