Python Help... Write a function stats() that takes one input argument: the name of a text file. The function should print, on the screen, the number of lines (line count), words(word count), and characters(character count) in the file; your function should open the file only once. Hints:Use the print format() module to print results and remember to save the function and the text file in the same directory.   def stats(filename): ' Put in docstring’ # get file content infile = _____________________ # ______________ content = ___________________ # ______________ infile ______________# __

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section8.3: Random File Access
Problem 6E
icon
Related questions
Topic Video
Question

Python Help...

Write a function stats() that takes one input argument: the name of a text file. The function should print, on the screen, the number of lines (line count), words(word count), and characters(character count) in the file; your function should open the file only once. Hints:Use the print format() module to print results and remember to save the function and the text file in the same directory.

 

def stats(filename):

' Put in docstring’

# get file content

infile = _____________________ # ______________

content = ___________________ # ______________

infile ______________# ______________

 

# replace punctuation with blank spaces and obtain list of words

table = ________________________ # _______________

words = _______________________ # _______________

 

print___________________________# _______________

print___________________________# _______________

print__________________________# _______________

 

How it should run

Result of running the function.

>>> stats('example.txt')

line count: 4

word count: 20

character count: 99

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

it says Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    stats('example.txt')
NameError: name 'stats' is not defined

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr