Command-line programs · 15 / 15 Exercise Hard

Complete program with main

Objective

Bring together everything you have learned in a well-structured program: small functions, a main function that receives the arguments and the if __name__ == "__main__" pattern. 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

  • Read from standard input lines with the format name,grade (integer grade).
  • Options with argparse: --min (integer, default 0, discards lower grades), --sort (name or grade, default name) and --format (text or csv, default text).
  • Sorting by name is alphabetical; by grade, from highest to lowest grade (ties by name). Format text shows name: grade and format csv, name,grade.
  • Write main(argv=None) that returns the exit code and finish with sys.exit(main()). If no student is left after filtering, write No results to the standard error (file=sys.stderr) and return 1.
Input
ana,8
luis,5
bea,9
Output
bea: 9
ana: 8
luis: 5

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

Start exercise