Brief
Create a simple explainable batch-checking command with numeric arguments, an optional name, automatic help and a failure signal.
In the story, Imani enters the evidence room with two colleagues. Voss insists your ID is enough to suspend you. Mara asks for a reproducible demonstration: batch P has 7 rows and 6 IDs; Q has 2 rows and 3 IDs; R has 0 and 0. The practice script is check.py; original receipts remain sealed. Say what you will type and what the computer must answer.
Your mission
- Write commands for P, Q and R with batch labels.
- Give expected output or refusal and exit code for each.
- Explain how to display help and distinguish required arguments from the option.
- Say what the demonstration proves and what still needs human investigation.
How to check your work
- Each command supplies two counts and
--labelfollowed by the name. - P gives 1 with code 0; Q is refused with code 2; R gives 0 with code 0.
--helpshows usage;7and6are required, while--label Pis optional.- The counting rule is repeatable; source and author of traces still need checking.
Course example
Workspace version: the sample arguments 5 and 4 are supplied in the code. The complete command-line program remains in the lesson.
import argparse
def main():
parser = argparse.ArgumentParser(description='Count repeated rows')
parser.add_argument('rows', type=int)
parser.add_argument('distinct', type=int)
parser.add_argument('--label', default='batch')
args = parser.parse_args(['5', '4'])
if args.rows < 0 or args.distinct < 0 or args.distinct > args.rows:
parser.error('impossible count')
repeats = args.rows - args.distinct
print(f'{args.label}: {repeats} repeat(s)')
return 0
if __name__ == '__main__':
main()