Qiusi Agre - C24 Crow#13
Conversation
mikellewade
left a comment
There was a problem hiding this comment.
Nice work on completing your first project, Qiusi!
| correct_letter_guess_statuses = build_letter_status_dict(snowman_word) | ||
| wrong_guesses_list = [] | ||
|
|
||
| print() |
There was a problem hiding this comment.
Seems like this was just leftover from development as it has no effects on your code. Make sure that you are doing a sweep on your codebase for inconsistencies in styling and stray lines of code like this.
| print() |
| wrong_guesses_list = [] | ||
|
|
||
| print() | ||
| print_word_progress_string(snowman_word, correct_letter_guess_statuses) |
| print() | ||
| print_word_progress_string(snowman_word, correct_letter_guess_statuses) | ||
|
|
||
| while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES: |
There was a problem hiding this comment.
Nice work with this while loop! We don't actually know how many times it will take a user to guess the word or hit the limit of wrong guesses (could keep make invalid guesses) so this the perfect choice for that situation!
| while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES: | ||
| user_input = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list) | ||
|
|
||
| if user_input in correct_letter_guess_statuses: |
There was a problem hiding this comment.
Note that the if user_input in correct_letter_guess_statuses is shorthand (in and not in) for:
for element in sequence:
if element == sought_after:
return True
return FalseYou can use this syntax to perform the above logic over a multiple kinds of iterables/sequences in Python. Later in the curriculum we will learn that they don't all have the same performance (Big O).
| print("You guessed a letter that's in the word!") | ||
| correct_letter_guess_statuses[user_input] = True | ||
| else: | ||
| print(f"The letter {user_input} is not in the word") | ||
| wrong_guesses_list.append(user_input) |
There was a problem hiding this comment.
A common rule of thumb is to perform the an operation and then after it is successful alert the user. This is so that there are no false positives sent to the user just in case of some failure in your code after the alert is since. With the print line being placed after it can only execute upon success of the prior lines.
| print("You guessed a letter that's in the word!") | |
| correct_letter_guess_statuses[user_input] = True | |
| else: | |
| print(f"The letter {user_input} is not in the word") | |
| wrong_guesses_list.append(user_input) | |
| correct_letter_guess_statuses[user_input] = True | |
| print("You guessed a letter that's in the word!") | |
| else: | |
| wrong_guesses_list.append(user_input) | |
| print(f"The letter {user_input} is not in the word") |
| wrong_guesses_list.append(user_input) | ||
|
|
||
| print_snowman_graphic(len(wrong_guesses_list)) | ||
| print(f"Wrong guesses: {wrong_guesses_list}") |
There was a problem hiding this comment.
Love that you included this! Make it easier on players by not forcing them to try and recall their previous guesses. For a better user experience, how could we alter this print statement so that the [] aren't wrapped around the guesses of a player? Recall, you would most likely have someone playing this game that doesn't have knowledge of Python. They'd most likely be thrown off by the random (to them) [] and "".
| if is_word_guessed(snowman_word, correct_letter_guess_statuses): | ||
| print("Congratulations, you win!") | ||
| return |
There was a problem hiding this comment.
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. Something to consider here is readability, imagine if we decided to structure our loop like the following:
while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES and is_word_guessed(snowman_word, correct_letter_guess_statuses): Which one more readily communicates to developers that this while loop is break condition is partially dependent on if the word is guessed? Why? (Note the checks themselves would function the same, though the following code of the modified while statement would look different in some places).
No description provided.