|
5 | 5 |
|
6 | 6 | def main(): |
7 | 7 | parser = argparse.ArgumentParser( |
8 | | - description="Probability Calculator — Monte-Carlo simulation for drawing balls from a hat." |
| 8 | + description=( |
| 9 | + "Probability Calculator — Monte-Carlo simulation for drawing " |
| 10 | + "colored balls from a hat." |
| 11 | + ) |
9 | 12 | ) |
10 | 13 |
|
11 | 14 | parser.add_argument( |
12 | 15 | "--hat", |
13 | 16 | nargs="+", |
14 | | - help="Colors and counts, e.g. red=3 blue=2", |
| 17 | + help="Colors and counts: e.g. red=3 blue=2 green=6", |
15 | 18 | ) |
| 19 | + |
16 | 20 | parser.add_argument( |
17 | 21 | "--expect", |
18 | 22 | nargs="+", |
19 | | - help="Expected ball counts, e.g. red=2 blue=1", |
| 23 | + help="Required minimum colors: e.g. red=2 green=1", |
| 24 | + ) |
| 25 | + |
| 26 | + parser.add_argument( |
| 27 | + "--draw", |
| 28 | + type=int, |
| 29 | + help="Number of balls to draw.", |
| 30 | + ) |
| 31 | + |
| 32 | + parser.add_argument( |
| 33 | + "--experiments", |
| 34 | + type=int, |
| 35 | + help="Number of Monte-Carlo experiments.", |
20 | 36 | ) |
21 | | - parser.add_argument("--draw", type=int, help="Number of balls drawn") |
22 | | - parser.add_argument("--experiments", type=int, help="Number of experiments") |
23 | 37 |
|
24 | 38 | args = parser.parse_args() |
25 | 39 |
|
| 40 | + # Must pass all required arguments |
26 | 41 | if not (args.hat and args.expect and args.draw and args.experiments): |
27 | 42 | parser.print_help() |
28 | 43 | return |
29 | 44 |
|
30 | | - # Convert hat arguments |
| 45 | + # Parse hat contents |
31 | 46 | hat_kwargs = {} |
32 | 47 | for item in args.hat: |
33 | 48 | color, count = item.split("=") |
34 | 49 | hat_kwargs[color] = int(count) |
35 | 50 |
|
| 51 | + # Parse expected outcome |
36 | 52 | expected = {} |
37 | 53 | for item in args.expect: |
38 | 54 | color, count = item.split("=") |
|
0 commit comments