From 5c6e22c6031b871673881c8745a159a8b55e099c Mon Sep 17 00:00:00 2001 From: Xueyan Zhang Date: Fri, 15 May 2026 00:16:17 -0400 Subject: [PATCH] Fix consecutive-wins bug in solution - remove uninitialized `runner.consecutive_wins` attribute - roll the dice each round --- solutions/dicegame/runner.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/solutions/dicegame/runner.py b/solutions/dicegame/runner.py index 7456360..d7c3085 100644 --- a/solutions/dicegame/runner.py +++ b/solutions/dicegame/runner.py @@ -1,4 +1,4 @@ -from .die import Die +from .die import Die, roll from .utils import i_just_throw_an_exception class GameRunner: @@ -21,12 +21,14 @@ def answer(self): @classmethod def run(cls): - count = 0 + consecutive_wins = 0 runner = cls() while True: print("Round {}\n".format(runner.round)) + roll(runner.dice) + for die in runner.dice: print(die.show()) @@ -36,18 +38,17 @@ def run(cls): if guess == runner.answer: print("Congrats, you can add like a 5 year old...") runner.wins += 1 - count += 1 - runner.consecutive_wins += 1 + consecutive_wins += 1 else: print("Sorry that's wrong") print("The answer is: {}".format(runner.answer)) print("Like seriously, how could you mess that up") runner.loses += 1 - count = 0 + consecutive_wins = 0 print("Wins: {} Loses {}".format(runner.wins, runner.loses)) runner.round += 1 - if count == 6: + if consecutive_wins == 6: print("You won... Congrats...") print("The fact it took you so long is pretty sad") break