Write a function called "wc", which stands for word count (a unix utility). wc takes one string as input, which should be the name of a text file. wc prints on one line, the number of lines, the number of words, and the number of characters in the file (three numbers separated by tabs). Hint: Use word_count as a subroutine; and \t gives the tab character.
(The code is to be written in python)
In case of any query do comment. Please rate answer as well. Thanks
Code:
def wc(file):
numberOfLetters =0
numberOfWords = 0
numberOfLines =0
#read file line by line
for line in file:
#incremented the numberOfLines by 1
numberOfLines +=1
#split the line to get words
words = line.strip().split()
#update the count of words
numberOfWords += len(words)
#inside each word count the letters and update the count of letters
for word in words:
for letter in word:
numberOfLetters +=1
#print the output in one line seperated by tab
print("{}\t{}\t{}".format(numberOfLines,numberOfWords,numberOfLetters))
#main driver program
file = open("input.txt")
wc(file)
========Screen shot of the code========

Output:

Write a function called "wc", which stands for word count (a unix utility). wc takes one...