diff --git a/game.py b/game.py index 493a74a..ff9f3d8 100644 --- a/game.py +++ b/game.py @@ -17,25 +17,46 @@ def snowman(snowman_word): """Complete the snowman function replace "pass" below with your own code It should print 'Congratulations, you win!' - If the player wins and, + If the player wins and, 'Sorry, you lose! The word was {snowman_word}' if the player loses """ - pass + correct_letter_guess_statuses = build_letter_status_dict(snowman_word) + wrong_guesses_list = [] + + while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES and not is_word_guessed(snowman_word, correct_letter_guess_statuses) : + + user_input = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list) + + if user_input in snowman_word : + print("You guessed a letter that's in the word!") + correct_letter_guess_statuses[user_input] = True + print(generate_word_progress_string(snowman_word, correct_letter_guess_statuses)) + + else : + print(f"The letter {user_input} is not in the word!") + wrong_guesses_list.append(user_input) + print_snowman_graphic(len(wrong_guesses_list)-1) + + if is_word_guessed(snowman_word, correct_letter_guess_statuses) : + print("Congratulations, you win!") + else : + print(f"Sorry, you lose! The word was {snowman_word}") + def print_snowman_graphic(wrong_guesses_count): - """This function prints out the appropriate snowman image + """This function prints out the appropriate snowman image depending on the number of wrong guesses the player has made. """ - + for i in range(SNOWMAN_MAX_WRONG_GUESSES - wrong_guesses_count, SNOWMAN_MAX_WRONG_GUESSES): print(SNOWMAN_GRAPHIC[i]) 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 snowman_word_dict 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 + It asks for input from the user of a single character until a valid character is provided and then returns this character. """ @@ -48,8 +69,8 @@ def get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list): print("You must input a letter!") elif len(user_input_string) > 1: print("You can only input one letter at a time!") - elif (user_input_string in correct_letter_guess_statuses - and correct_letter_guess_statuses[user_input_string]): + elif (user_input_string in correct_letter_guess_statuses + and correct_letter_guess_statuses[user_input_string]): print("You already guessed that letter and it's in the word!") elif user_input_string in wrong_guesses_list: print("You already guessed that letter and it's not in the word!") @@ -57,11 +78,11 @@ def get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list): valid_input = True return user_input_string - + def build_letter_status_dict(snowman_word): - """This function takes snowman_word as input and returns - a dictionary with a key-value pair for each letter in + """This function takes snowman_word as input and returns + a dictionary with a key-value pair for each letter in snowman_word where the key is the letter and the value is `False`. """ @@ -69,12 +90,12 @@ def build_letter_status_dict(snowman_word): for letter in snowman_word: letter_status_dict[letter] = False return letter_status_dict - + def print_word_progress_string(snowman_word, correct_letter_guess_statuses): """ This function takes the snowman_word and snowman_word_dict as input. - It calls another function to generate a string representation of the + It calls another function to generate a string representation of the user's progress towards guessing snowman_word and prints this string. """ @@ -85,8 +106,8 @@ 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. - 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 + 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. """