Command-line programs · 11 / 15 Exercise Medium

Statistics of a list of numbers

Objective

Create a program with argparse that computes statistics of a list of numbers passed as arguments. 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

  • Positional argument numbers with nargs="+" (one or more values) and type=float (it converts them to float).
  • Option --decimals (integer, default 2): decimals used to show the results.
  • Show Count: k, Average: m, Minimum: x and Maximum: y (the last three with that number of decimals).
  • If no number is given, argparse ends with exit code 2.
Output
Count: 3
Average: 9.00
Minimum: 4.00
Maximum: 15.00

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise