From 90c88b43853e6fdf8fd8c7c1ae4d7c003768fac7 Mon Sep 17 00:00:00 2001 From: mollychi Date: Sun, 9 Nov 2025 20:49:15 -0500 Subject: [PATCH] I just addded the docstrings My thinking was more backward in this question, seeing waht we had to write what it was going to give us, when i code its more forward thinkinhg I might include it, it is easy but also if im sturggling i wont want to, ill just want to code it and be done lol --- yahtzee.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/yahtzee.py b/yahtzee.py index 69b0e97..5fe7e9b 100644 --- a/yahtzee.py +++ b/yahtzee.py @@ -10,6 +10,10 @@ class Yahtzee: self.dice = [Die() for num in range(5)] def play(self): + """ Play an entire game. + Starts by greeting the user, then plays rounds until all the goals + have been used. When the game is over, tells the player their final + score.""" print("Welcome to Yachtzee!") self.score = 0 for goal in self.goals: @@ -19,6 +23,8 @@ class Yahtzee: print(f"Your final score was {self.score}") def play_round(self): + """This just rolls the dice and figures out what each number was + rolled on each dice""" print("=" * 80) self.rolls_left = 3 for die in self.dice: @@ -29,10 +35,13 @@ class Yahtzee: self.score += goal.score(self.dice) def show_status(self): + """This shows the player their rolls""" dice = ', '.join([str(die) for die in self.dice]) print(f"Score: {self.score}. Rolls left: {self.rolls_left}. Dice: {dice}.") def choose_goal(self): + """ shwos them the number of 1's 2's and 3's + and offers them the options of rerolling or keeping their rolls""" options = [] unused_goals = self.get_unused_goals() for goal in unused_goals: @@ -49,6 +58,7 @@ class Yahtzee: return unused_goals[choice] def get_choice(self, options): + """ gives feedback to help the player decide what to do next""" print("What would you like to do?") for i, option in enumerate(options): print(f"{i}. {option}") @@ -59,6 +69,7 @@ class Yahtzee: return int(choice) def option_choice_is_valid(self, choice, options): + """Makes sure that what the player puts in is usable """ if not choice.isdigit(): return False if int(choice) < 0: @@ -78,6 +89,8 @@ class Yahtzee: return unused_goals def reroll(self): + """If the player decides to reroll, this is what the computer must to + to start that process""" self.rolls_left -= 1 choices = self.get_reroll_choices() dice_to_reroll = self.get_dice_to_reroll(choices) @@ -85,6 +98,8 @@ class Yahtzee: die.roll() def get_dice_to_reroll(self, choice_ints): + """If the player decides to reroll, this is what the computer must to + to start that process""" dice_to_reroll = [] for die in self.dice: if die.face in choice_ints: @@ -93,6 +108,8 @@ class Yahtzee: return dice_to_reroll def get_reroll_choices(self): + """Asks the player what dice number do they want to reroll, all dice of that + number will be rerolled""" print("Which dice do you want to re-roll?") choices = input("> ") while not self.reroll_choices_are_valid(choices): @@ -102,6 +119,7 @@ class Yahtzee: return choice_ints def reroll_choices_are_valid(self, choices_str): + """This is the code to adjust for the reroll """ if not choices_str.isdigit(): return False choice_ints = [int(digit) for digit in choices_str]