Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@ def snowman(snowman_word):
If the player wins and,
'Sorry, you lose! The word was {snowman_word}' if the player loses
"""
pass

wrong_guesses_list = []
correct_letter_guess_statuses = build_letter_status_dict(snowman_word)

while len(wrong_guesses_list) <= SNOWMAN_MAX_WRONG_GUESSES:
letter_typed = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list)
if letter_typed in snowman_word:
correct_letter_guess_statuses[letter_typed] = True
print_word_progress_string(snowman_word, correct_letter_guess_statuses)

if is_word_guessed(snowman_word, correct_letter_guess_statuses) is True:
print("Congratulations, you win!")
return
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of the return keyword. This allows for us to exit not only the while loop early if this condition is met but also the function as a whole.

else:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code is missing an implementation of one of the requirements. Your snowman function should display the list of incorrect guesses. @ra-choa please respond to this comment with how you would implement this feature.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Mikelle, I missed this because I only looked at the readme and forgot to refer back to the Learn page. Updated accordingly here 🫡

wrong_guesses_list.append(letter_typed)
print_snowman_graphic(len(wrong_guesses_list))
print(f"wrong letters: {wrong_guesses_list}")
if len(wrong_guesses_list) >= SNOWMAN_MAX_WRONG_GUESSES:
print(f"Sorry, you lose! The word was {snowman_word}")
return

def print_snowman_graphic(wrong_guesses_count):
"""This function prints out the appropriate snowman image
Expand All @@ -33,7 +50,7 @@ def print_snowman_graphic(wrong_guesses_count):


def get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list):
"""This function takes the snowman_word_dict and the list of characters
"""This function takes the correct_letter_guess_statuses and the list of characters
that have been guessed incorrectly (wrong_guesses_list) as input.
It asks for input from the user of a single character until
a valid character is provided and then returns this character.
Expand Down Expand Up @@ -73,7 +90,7 @@ def build_letter_status_dict(snowman_word):

def print_word_progress_string(snowman_word, correct_letter_guess_statuses):
"""
This function takes the snowman_word and snowman_word_dict as input.
This function takes the snowman_word and correct_letter_guess_statuses as input.
It calls another function to generate a string representation of the
user's progress towards guessing snowman_word and prints this string.
"""
Expand All @@ -84,7 +101,7 @@ def print_word_progress_string(snowman_word, correct_letter_guess_statuses):

def generate_word_progress_string(snowman_word, correct_letter_guess_statuses):
"""
This function takes the snowman_word and snowman_word_dict as input.
This function takes the snowman_word and correct_letter_guess_statuses as input.
It creates and returns an output string that shows the correct letter
guess placements as well as the placements for the letters yet to be
guessed.
Expand All @@ -109,7 +126,7 @@ def generate_word_progress_string(snowman_word, correct_letter_guess_statuses):

def is_word_guessed(snowman_word, correct_letter_guess_statuses):
"""
This function takes the snowman_word and snowman_word_dict as input.
This function takes the snowman_word and correct_letter_guess_statuses as input.
It returns True if all the letters of the word have been guessed, and False otherwise.
"""

Expand Down