diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2024-08-22 17:49:24 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2024-08-22 18:04:41 -0400 |
| commit | 72a36d40d50f47134a1ffbf5f995e168451ac6a2 (patch) | |
| tree | 9e0bfc87a92507f17bcd6a78c657212f41ebb283 /scripts/roll-die | |
| parent | 935d6645c4d94835e60b583d2856960a098fd783 (diff) | |
configuration for basedpyright and ruff
Diffstat (limited to 'scripts/roll-die')
| -rwxr-xr-x | scripts/roll-die | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/scripts/roll-die b/scripts/roll-die index 8135b0b..6cb277a 100755 --- a/scripts/roll-die +++ b/scripts/roll-die @@ -6,17 +6,17 @@ from pathlib import Path import re -def roll_die(num_dice: int, dice_type: int, modifier: int) -> [int]: - rolls = [] - for i in range(num_dice): +def roll_die(num_dice: int, dice_type: int, modifier: int) -> list[int]: + rolls: list[int] = [] + for _ in range(num_dice): rolls.append(random.randint(1, dice_type) + modifier) return rolls -def parse_dice_notation(dice_notation) -> (int, int, int): +def parse_dice_notation(dice_notation: str) -> tuple[int, int, int]: # Define the regular expression pattern - pattern = re.compile(r'(\d+)d(\d+)([+-]\d+)?') + pattern = re.compile(r"(\d+)d(\d+)([+-]\d+)?") # Search the pattern in the dice notation string match = pattern.match(dice_notation) @@ -35,13 +35,13 @@ def parse_dice_notation(dice_notation) -> (int, int, int): return num_dice, dice_type, modifier -def summary(rolls: [int]) -> None: +def summary(rolls: list[int]) -> None: print(rolls) - print(f'Min: {min(rolls)}') - print(f'Max: {max(rolls)}') + print(f"Min: {min(rolls)}") + print(f"Max: {max(rolls)}") if len(rolls) > 1: - print(f'Total: {sum(rolls)}') - print(f'Avg: {sum(rolls)/len(rolls):.2f}') + print(f"Total: {sum(rolls)}") + print(f"Avg: {sum(rolls)/len(rolls):.2f}") def main(): @@ -61,6 +61,7 @@ def main(): num_die, die_type, modifier = parse_dice_notation(dice_notation) except ValueError as e: print(e) + sys.exit(1) rolls = roll_die(num_die, die_type, modifier) summary(rolls) |
