From 55dad10f8f8c370cbb50f8571de6cbf3fea595ae Mon Sep 17 00:00:00 2001 From: Laura Castro <104328428+lauracastrotech@users.noreply.github.com> Date: Sun, 16 Feb 2025 17:58:34 -0500 Subject: [PATCH 1/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 337fd00..6f7a60f 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ $ pip install -r requirements.txt ``` Summary of one-time project setup: -- [ ] Fork the project respository +- [ x ] Fork the project respository - [ ] `cd` into your `projects` folder - [ ] Clone the project onto your machine - [ ] `cd` into the `snowman` folder @@ -86,4 +86,4 @@ You will be prompted to enter "p" to play the game, or "t" to run the tests. When you start, all of the tests will fail, and playing the game will exit the program immediately. Your goal is to make the tests pass and the game work! -To do this, you will need to complete the implementation of the `snowman` function in the file `game.py`. There are a number of other functions that we developed in the Precourse materials that are also included in that file for you to use. \ No newline at end of file +To do this, you will need to complete the implementation of the `snowman` function in the file `game.py`. There are a number of other functions that we developed in the Precourse materials that are also included in that file for you to use. From f4528ed974a7566bf93e3f75381e30c5d2aca964 Mon Sep 17 00:00:00 2001 From: Laura Castro <104328428+lauracastrotech@users.noreply.github.com> Date: Sun, 16 Feb 2025 17:59:24 -0500 Subject: [PATCH 2/7] Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6f7a60f..793ee95 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,13 @@ $ pip install -r requirements.txt ``` Summary of one-time project setup: -- [ x ] Fork the project respository -- [ ] `cd` into your `projects` folder -- [ ] Clone the project onto your machine -- [ ] `cd` into the `snowman` folder -- [ ] Create the virtual environment `venv` -- [ ] Activate the virtual environment `venv` -- [ ] Install the dependencies with `pip` +- [x] Fork the project respository +- [x] `cd` into your `projects` folder +- [x] Clone the project onto your machine +- [x] `cd` into the `snowman` folder +- [x] Create the virtual environment `venv` +- [x] Activate the virtual environment `venv` +- [x] Install the dependencies with `pip` # Running the Project From 5cac39c29a25896af3b8b64a2aecaff4b14d0732 Mon Sep 17 00:00:00 2001 From: Laura Castro Date: Tue, 25 Feb 2025 11:17:51 -0500 Subject: [PATCH 3/7] hard code correct guesses counter to end loop and terminate function --- game.py | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/game.py b/game.py index 493a74a..aa07c62 100644 --- a/game.py +++ b/game.py @@ -20,7 +20,37 @@ def snowman(snowman_word): 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: + # Ask user to guess a letter + user_input = get_letter_from_user(wrong_guesses_list, correct_letter_guess_statuses) + + # Check if the letter is in the word + if user_input in snowman_word: + # Set value of correct letter to True + correct_letter_guess_statuses[user_input] = True + correct += 1 + # Check if the word has been guessed + if is_word_guessed(snowman_word, correct_letter_guess_statuses): + print('Congratulations, you win!') + # print('you win') + return + else: + # Add wrong letter to wrong guesses list + wrong_guesses_list.append(user_input) + + # User's progress with correct letters + print_word_progress_string(snowman_word, correct_letter_guess_statuses) + + # Show snowman + print_snowman_graphic(len(wrong_guesses_list)) + + # When the user has no more guesses, they lose + print(f'Sorry, you lose! The word was {snowman_word}') + def print_snowman_graphic(wrong_guesses_count): @@ -48,8 +78,7 @@ 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!") @@ -64,7 +93,6 @@ def build_letter_status_dict(snowman_word): a dictionary with a key-value pair for each letter in snowman_word where the key is the letter and the value is `False`. """ - letter_status_dict = {} for letter in snowman_word: letter_status_dict[letter] = False @@ -82,7 +110,8 @@ def print_word_progress_string(snowman_word, correct_letter_guess_statuses): print(progress_string) -def generate_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 From 084d50245a605bd601363cd8a175816301da23ad Mon Sep 17 00:00:00 2001 From: Laura Castro Date: Wed, 26 Feb 2025 14:34:52 -0500 Subject: [PATCH 4/7] fix arguments position for get_letter_from_user function() --- game.py | 12 ++++++------ main.py | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/game.py b/game.py index aa07c62..7c09a8e 100644 --- a/game.py +++ b/game.py @@ -12,7 +12,6 @@ '-----------' ] - def snowman(snowman_word): """Complete the snowman function replace "pass" below with your own code @@ -21,22 +20,22 @@ def snowman(snowman_word): 'Sorry, you lose! The word was {snowman_word}' if the player loses """ correct_letter_guess_statuses = build_letter_status_dict(snowman_word) + print(correct_letter_guess_statuses) + print(type(correct_letter_guess_statuses)) wrong_guesses_list = [] while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES: # Ask user to guess a letter - user_input = get_letter_from_user(wrong_guesses_list, correct_letter_guess_statuses) + user_input = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list) # Check if the letter is in the word if user_input in snowman_word: # Set value of correct letter to True correct_letter_guess_statuses[user_input] = True - correct += 1 # Check if the word has been guessed if is_word_guessed(snowman_word, correct_letter_guess_statuses): print('Congratulations, you win!') - # print('you win') return else: # Add wrong letter to wrong guesses list @@ -50,8 +49,7 @@ def snowman(snowman_word): # When the user has no more guesses, they lose 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 @@ -74,6 +72,8 @@ def get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list): while not valid_input: user_input_string = input("Guess a letter: ") + + # print(correct_letter_guess_statuses[user_input_string]) if not user_input_string.isalpha(): print("You must input a letter!") elif len(user_input_string) > 1: diff --git a/main.py b/main.py index c60c994..a1e36a3 100644 --- a/main.py +++ b/main.py @@ -9,8 +9,7 @@ if user_input == "p": from game import snowman, SNOWMAN_MIN_WORD_LENGTH, SNOWMAN_MAX_WORD_LENGTH from wonderwords import RandomWord - - random_word_generator = RandomWord() + random_word_generator = RandomWord() snowman_word = random_word_generator.word(word_min_length=SNOWMAN_MIN_WORD_LENGTH, word_max_length=SNOWMAN_MAX_WORD_LENGTH) snowman(snowman_word) From 5225e161b67002edf9b939f9a43d11c1ca63bd70 Mon Sep 17 00:00:00 2001 From: Laura Castro Date: Wed, 26 Feb 2025 14:36:54 -0500 Subject: [PATCH 5/7] remove comments a debugging print statements --- game.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/game.py b/game.py index 7c09a8e..88d131f 100644 --- a/game.py +++ b/game.py @@ -20,9 +20,6 @@ def snowman(snowman_word): 'Sorry, you lose! The word was {snowman_word}' if the player loses """ correct_letter_guess_statuses = build_letter_status_dict(snowman_word) - print(correct_letter_guess_statuses) - print(type(correct_letter_guess_statuses)) - wrong_guesses_list = [] while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES: @@ -73,7 +70,6 @@ def get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list): while not valid_input: user_input_string = input("Guess a letter: ") - # print(correct_letter_guess_statuses[user_input_string]) if not user_input_string.isalpha(): print("You must input a letter!") elif len(user_input_string) > 1: From 90b0e527b0cff9571b35b5355835e60de9344df3 Mon Sep 17 00:00:00 2001 From: Laura Castro Date: Thu, 6 Mar 2025 09:49:37 -0500 Subject: [PATCH 6/7] refactor logic in snowman function loop --- game.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/game.py b/game.py index 88d131f..1b1669c 100644 --- a/game.py +++ b/game.py @@ -21,32 +21,26 @@ def snowman(snowman_word): """ correct_letter_guess_statuses = build_letter_status_dict(snowman_word) wrong_guesses_list = [] + is_winner = False - while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES: - # Ask user to guess a letter + while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES and not is_winner: user_input = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list) - # Check if the letter is in the word if user_input in snowman_word: - # Set value of correct letter to True correct_letter_guess_statuses[user_input] = True - # Check if the word has been guessed - if is_word_guessed(snowman_word, correct_letter_guess_statuses): - print('Congratulations, you win!') - return + + if is_word_guessed(snowman_word, correct_letter_guess_statuses): + print('Congratulations, you win!') + is_winner = True else: - # Add wrong letter to wrong guesses list wrong_guesses_list.append(user_input) - # User's progress with correct letters print_word_progress_string(snowman_word, correct_letter_guess_statuses) - # Show snowman print_snowman_graphic(len(wrong_guesses_list)) - # When the user has no more guesses, they lose - print(f'Sorry, you lose! The word was {snowman_word}') - return + if not is_winner: + 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 From 315e5b2ee11a2cae3394d54a0d474409c3faca71 Mon Sep 17 00:00:00 2001 From: Laura Castro Date: Thu, 6 Mar 2025 10:26:47 -0500 Subject: [PATCH 7/7] assign number of wrong guesses to variable --- game.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/game.py b/game.py index 1b1669c..a5ce6ef 100644 --- a/game.py +++ b/game.py @@ -21,23 +21,25 @@ def snowman(snowman_word): """ correct_letter_guess_statuses = build_letter_status_dict(snowman_word) wrong_guesses_list = [] + num_wrong_guesses = len(wrong_guesses_list) is_winner = False - while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES and not is_winner: + while num_wrong_guesses < SNOWMAN_MAX_WRONG_GUESSES and not is_winner: user_input = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list) if user_input in snowman_word: correct_letter_guess_statuses[user_input] = True - + else: + wrong_guesses_list.append(user_input) + num_wrong_guesses += 1 + if is_word_guessed(snowman_word, correct_letter_guess_statuses): print('Congratulations, you win!') is_winner = True - else: - wrong_guesses_list.append(user_input) print_word_progress_string(snowman_word, correct_letter_guess_statuses) - - print_snowman_graphic(len(wrong_guesses_list)) + print_snowman_graphic(num_wrong_guesses) + print(f"Incorrect letters: {', '.join(wrong_guesses_list)}") if not is_winner: print(f'Sorry, you lose! The word was {snowman_word}')