Objective
Create a program that imitates the Unix wc command: it counts lines, words and characters of the text it receives through standard input, and is controlled with flags (options without a value). The arguments of each test are passed to the program as if you typed them in the terminal (they appear in the test cases).
Instructions
- Define with
argparsethe flags-l/--lines,-w/--wordsand-c/--chars(withaction="store_true"). - Read all the text with
sys.stdin.read(). Lines are obtained withsplitlines(); words, withsplit(); characters are those of the lines (without the line breaks). - Show
Lines: k,Words: kand/orCharacters: kdepending on the flags given. If none is given, show the three, in that order.
hola mundo
otra linea mas
Lines: 2
Words: 5
Characters: 24
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise