Vivian Soo - C24 Crow#26
Conversation
mikellewade
left a comment
There was a problem hiding this comment.
Great work on your first Ada project, Vivian!
| 'Sorry, you lose! The word was {snowman_word}' if the player loses | ||
| """ | ||
| pass | ||
| print(snowman_word) |
There was a problem hiding this comment.
Looks like this was left behind from testing. You'll want to scrub comments/lines like these from your codebase before making a PR. Leaving them behind can lead to bugs or a cluttered codebase.
| print(snowman_word) |
| correct_letter_guess_statuses = build_letter_status_dict(snowman_word) | ||
| wrong_guesses_list = [] |
There was a problem hiding this comment.
Consider adding a few blank lines within your function to separate logically distinct sections of the code (e.g., setup, processing, return). According to PEP 8, blank lines can improve readability by visually grouping related operations. Right now, everything runs together, which can make it harder to quickly understand the structure and flow of your function.
| correct_letter_guess_statuses = build_letter_status_dict(snowman_word) | |
| wrong_guesses_list = [] | |
| correct_letter_guess_statuses = build_letter_status_dict(snowman_word) | |
| wrong_guesses_list = [] | |
Adding a space below will visually separate this logic from the guessing logic, making it easier to digest.
| print(snowman_word) | ||
| correct_letter_guess_statuses = build_letter_status_dict(snowman_word) | ||
| wrong_guesses_list = [] | ||
| 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!
| wrong_guesses_list = [] | ||
| while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES: | ||
| print_word_progress_string(snowman_word, correct_letter_guess_statuses) | ||
| user_input = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list) |
There was a problem hiding this comment.
This line of characters exceeds (due to the indentation) the suggested 80 character limit for readability. You'd want to use the PEP 8 Style Guidelines for line continuation to break this up onto multiple lines.
| user_input = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list) | |
| user_input = get_letter_from_user( | |
| correct_letter_guess_statuses, | |
| wrong_guesses_list) | |
| while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES: | ||
| print_word_progress_string(snowman_word, correct_letter_guess_statuses) | ||
| 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 False
return TrueYou 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(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(f"The letter {user_input} is not in the word") | |
| wrong_guesses_list.append(user_input) | |
| 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.
For a better user experience, how could we alter this print statement so that the [] aren't wrapped around the guesses of a player?
| print(f"Wrong guesses: {wrong_guesses_list}") | |
| print(f"Wrong guesses: {wrong_guesses_list}") | |
| if (not is_word_guessed(snowman_word, correct_letter_guess_statuses) | ||
| and len(wrong_guesses_list) == SNOWMAN_MAX_WRONG_GUESSES): | ||
| print(f"Sorry, you lose! The word was {snowman_word}") | ||
| return | ||
| 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. An alternative solution would be to move this logic outside of the while loop. What do you think would be the advantages/disadvantages would be for that kind of solution?
No description provided.