Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING PYTHON 12- write a function named fileStats that takes two strings paramet

ID: 3826656 • Letter: U

Question

USING PYTHON 12- write a function named fileStats that takes two strings parameters,1-inFile the name of the input file and 2- outFile the name of the output file. The function should read and analyze the contents of an input file and writes the statistics it compiles to the output file. the statistics you should compute about the input file are: the numbers of characters, the numbers of words , the numbers of lines, the numbers of digits and the numbers of punctuaction marks.. Each statistics should be written in a separate line of the output file( hint : the string class contains constants named punctuation and digits).

Explanation / Answer

import string

def fileStats(inFile, outFile):
lineCount = 0
wordCount = 0
charCount = 0
digitsCount = 0
punctCount = 0
# it doesn't include any white space char count. Comment if you need that
with open(inFile, "r") as fh:
for line in fh:
lineCount += 1
words = line.split()
wordCount += len(words)
for word in words:
charCount += len(word)
for c in word:
if c in string.punctuation:
punctCount += 1
elif c.isdigit():
digitsCount += 1
with open(outFile, "w") as fw:
fw.write("Line count: " + str(lineCount) + " ")
fw.write("word count: " + str(wordCount) + " ")
fw.write("char count: " + str(charCount) + " ")
fw.write("digit count: " + str(digitsCount) + " ")
fw.write("punctuation count: " + str(punctCount) + " ")

# pastebin link: https://pastebin.com/xDqhdPbS