Command Palette

Search for a command to run...

Hectal
Phase 15: Python for APIs, Services and Tools
Python · Exercise 5 of 6 PreviousNext
Intermediate

Build a command-line parser

Fill in build_parser() so it returns the parser with three things: a required positional argument name, an option --times (a whole number, default 1), and a flag --shout (off unless given).

Fill in run(argv). argv is a list of words such as ["Asha", "--times", "2"]. Parse it and return a list of greeting lines: the text Hello, <name>! repeated times times. If --shout was given, make every line capitals (HELLO, ASHA!).

What Check tests

  1. a plain greeting
  2. --times repeats
  3. --shout uses capitals
  4. times is converted to an integer
  5. option order does not matter, and --times 0 gives no lines
  6. a non-number for --times exits

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.