
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

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

it says Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
stats('example.txt')
NameError: name 'stats' is not defined
it says Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
stats('example.txt')
NameError: name 'stats' is not defined
- C programming language Criteria graded: Declare file pointers Open file Read from file Write to file Close file Instructions: Write a segment of code that opens a file called “numbers.txt” for reading. This file is known to have 10 numbers in it. Read in each number and print a ‘*’ to the screen if the number is even. If the number is odd, do nothing. Conclude by closing this file.arrow_forwardWhat type of object do you create if you want to read data from a text file?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





