Write a python function to Count the Number of Words in a Text File and print it


Topic: Write a python function to Count the Number of Words in a Text File and print it

Solution

def word_count(fname) : 
    num_words = 0
    with open(fname, 'r') as f:
        for line in f:
            words = line.split()
            num_words += len(words)
    print(num_words)



List all Python Programs