Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm trying to make a program file_stats.py that, when run on the command line, accepts a text file name as an argument and outputs the

I'm trying to make a program "file_stats.py" that, when run on the command line, accepts a text file name as an argument and outputs the number of characters(e.g., size of the file), words, lines, and the length (in characters) of the longest line in the file

$python file_stats.py beautiful_soup_by_Lewis_Carroll.txt Characters: 553 Words: 81 Lines: 21 Longest line: 38 $ python file_stats.py books.csv Characters: 557 Words: 45 Lines: 6 Longest line: 120 

The program should have a function stats that takes the filename as an input and returns the statistics (in the same order) as a tuple, so it can also be used in the REPL

 >>> from file_stats import stats >>> c, w, l, ll = stats('beautiful_soup_by_Lewis_Carroll.txt') >>> print(f"characters: {c}, words: {w}, lines: {l}, longest: {ll}") characters: 553, words: 81, lines: 21, longest: 38 

What I have so far:

import sys

def stats(filename):

# Do the calculations and return the data

pass

if __name__ == '__main__':

# call stats(filename) and print the results shown in instructions.

pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

What is American Polity and Governance ?

Answered: 1 week ago

Question

What is Constitution, Political System and Public Policy? In India

Answered: 1 week ago

Question

What is Environment and Ecology? Explain with examples

Answered: 1 week ago