$ python3 prog.py usage: prog.py [-h] [-v] square prog.py: error: the following arguments are required: square $ python3 prog.py 4 16 $ python3 prog.py 4--verbose the square of 4 equals 16 $ python3 prog.py --verbose 4 the square of 4 equals 16 • We’ve brought back a positional argument, hence the complaint. • Note that the order does not matter. How about we give this program of ours back the ability to have multiple verbosity values, and actually get to use them: import argparse parser =argparse.ArgumentParser() parser.add_argument( "square",type=int, help="display a square of a given number ") parser.add_argument( "-v ","--verbosity ",type=int, help="increase output verbosity ") args =parser.parse_args() answer =args.square**2 if args.verbosity ==2: print("the square of {} equals {} ".format(args .square, answer)) elif args.verbosity ==1: print(" {} ^2 == {} ".format(args .square, answer)) else : print(answer) $ python3 prog.py 4 16 $ python3 prog.py 4-v usage: prog.py [-h] [-v VERBOSITY] square prog.py: error: argument -v/--verbosity: expected one argument $ python3 prog.py 4-v1 4^2 == 16 $ python3 prog.py 4-v2 the square of 4 equals 16 $ python3 prog.py 4-v3 16 And the output: These all look good except the last one, which exposes a bug in our program. Let’s fix it by restricting the values the --verbosity option can accept: import argparse parser =argparse.ArgumentParser() parser.add_argument( "square",type=int, help="display a square of a given number ") parser.add_argument( "-v ","--verbosity ",type=int, choices=[0,1,2], help="increase output verbosity ") args =parser.parse_args() answer =args.square**2 if args.verbosity ==2: print("the square of {} equals {} ".format(args .square, answer)) elif args.verbosity ==1: print(" {} ^2 == {} ".format(args .square, answer)) else : print(answer) 7