From f1cb57c55edfda439e488b429c7acbd82400eceb Mon Sep 17 00:00:00 2001 From: bhunesh Date: Mon, 17 Aug 2026 01:36:55 +0530 Subject: [PATCH 1/2] Add interactive dice_roller.py implementation (Closes #3202) --- dice_roller.py | 109 +++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/dice_roller.py b/dice_roller.py index de805c61646..ea987e9e8ef 100644 --- a/dice_roller.py +++ b/dice_roller.py @@ -1,57 +1,58 @@ import random -dice_art = { - 1: ("┌─────────┐", - "│ │", - "│ ● │", - "│ │", - "└─────────┘"), - 2: ("┌─────────┐", - "│ ● │", - "│ │", - "│ ● │", - "└─────────┘"), - 3: ("┌─────────┐", - "│ ● │", - "│ ● │", - "│ ● │", - "└─────────┘"), - 4: ("┌─────────┐", - "│ ● ● │", - "│ │", - "│ ● ● │", - "└─────────┘"), - 5: ("┌─────────┐", - "│ ● ● │", - "│ ● │", - "│ ● ● │", - "└─────────┘"), - 6: ("┌─────────┐", - "│ ● ● │", - "│ ● ● │", - "│ ● ● │", - "└─────────┘") -} - -dice = [] -total = 0 -num_of_dice = int(input("How many dice?: ")) - -for die in range(num_of_dice): - dice.append(random.randint(1, 6)) - -# PRINT VERTICALLY -# for die in range(num_of_dice): -# for line in dice_art.get(dice[die]): -# print(line) - -# PRINT HORIZONTALLY -for line in range(5): - for die in dice: - print(dice_art.get(die)[line], end="") - print() - -for die in dice: - total += die -print(f"total: {total}") \ No newline at end of file +def get_die_art(value): + """Returns a list of 5 strings representing the box-drawing art + + for a given die face value (1-6). + """ + faces = { + 1: ["┌───────┐", "│ │", "│ ● │", "│ │", "└───────┘"], + 2: ["┌───────┐", "│ ● │", "│ │", "│ ● │", "└───────┘"], + 3: ["┌───────┐", "│ ● │", "│ ● │", "│ ● │", "└───────┘"], + 4: ["┌───────┐", "│ ● ● │", "│ │", "│ ● ● │", "└───────┘"], + 5: ["┌───────┐", "│ ● ● │", "│ ● │", "│ ● ● │", "└───────┘"], + 6: ["┌───────┐", "│ ● ● │", "│ ● ● │", "│ ● ● │", "└───────┘"], + } + return faces.get(value, faces[1]) + + +def main(): + print("========================================") + print(" Interactive Dice Roller ") + print("========================================") + + # Get valid user input for the number of dice + while True: + try: + num_dice = int(input("How many dice would you like to roll? (1-10): ")) + if 1 <= num_dice <= 10: + break + print("Please choose a number between 1 and 10.") + except ValueError: + print("Invalid input. Please enter a valid integer.") + + # Generate random values for each die + rolls = [random.randint(1, 6) for _ in range(num_dice)] + + print(f"\nRolling {num_dice} dice...") + print("~" * (num_dice * 11)) + + # Retrieve ASCII art for each rolled die + dice_arts = [get_die_art(val) for val in rolls] + + # Print dice side-by-side by iterating line by line (0 to 4) + for line_index in range(5): + row_line = " ".join(dice_art[line_index] for dice_art in dice_arts) + print(row_line) + + print("~" * (num_dice * 11)) + + # Output results and total sum + print(f"Individual Rolls: {rolls}") + print(f"Total Sum: {sum(rolls)}") + print("========================================") + + +if __name__ == "__main__": + main() From 6f3b57ad3b3ade78b5bba8a26671a3ae0ad14267 Mon Sep 17 00:00:00 2001 From: bhunesh Sharma Date: Mon, 17 Aug 2026 01:40:56 +0530 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- dice_roller.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dice_roller.py b/dice_roller.py index ea987e9e8ef..e2bd77fcd5f 100644 --- a/dice_roller.py +++ b/dice_roller.py @@ -36,17 +36,21 @@ def main(): rolls = [random.randint(1, 6) for _ in range(num_dice)] print(f"\nRolling {num_dice} dice...") - print("~" * (num_dice * 11)) # Retrieve ASCII art for each rolled die dice_arts = [get_die_art(val) for val in rolls] + separator = " " + die_width = len(dice_arts[0][0]) + divider = "~" * (num_dice * die_width + (num_dice - 1) * len(separator)) + print(divider) + # Print dice side-by-side by iterating line by line (0 to 4) for line_index in range(5): - row_line = " ".join(dice_art[line_index] for dice_art in dice_arts) + row_line = separator.join(dice_art[line_index] for dice_art in dice_arts) print(row_line) - print("~" * (num_dice * 11)) + print(divider) # Output results and total sum print(f"Individual Rolls: {rolls}")