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
- a plain greeting
- --times repeats
- --shout uses capitals
- times is converted to an integer
- option order does not matter, and --times 0 gives no lines
- 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.