Veema Jhagru - C24 Crow#25
Conversation
mikellewade
left a comment
There was a problem hiding this comment.
Veema, great work on completing the first Ada project!
| correct_letter_guess_statuses = build_letter_status_dict(snowman_word) | ||
|
|
||
| while wrong_guesses_count < SNOWMAN_MAX_WRONG_GUESSES: | ||
| 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) |
| wrong_guesses_list = [] | ||
| correct_letter_guess_statuses = build_letter_status_dict(snowman_word) | ||
|
|
||
| while wrong_guesses_count < 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!
| 'Sorry, you lose! The word was {snowman_word}' if the player loses | ||
| """ | ||
| pass | ||
| wrong_guesses_count = 0 |
There was a problem hiding this comment.
This variable to track the number of wrong guesses isn't necessary. Any time we need to know the count, we can get the length of the wrong guesses list. While there is a small bit of efficiency gained by not needing to call len(), the danger (not so much here, but in more complex code) is that we could update one of the list or the count in one location, but forget to update the other, meaning they are now out of sync.
| while wrong_guesses_count < SNOWMAN_MAX_WRONG_GUESSES: | ||
| user_input = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list) | ||
|
|
||
| if user_input in snowman_word and not correct_letter_guess_statuses[user_input]: |
There was a problem hiding this comment.
Note that the if user_guess in correct_letter_guess_statuses is shorthand (in and not in) for:
for letter in snowman_word:
if user_guess == letter:
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).
For the second half of your conditional, it essentially checks if the letter has been guessed correctly already or not. Keep in mind that the helper function get_letter_from_user performs this logic already. It is a redundancy to check it here. You could remove this piece of code.
| if user_input in snowman_word and not correct_letter_guess_statuses[user_input]: | |
| if user_input in snowman_word: |
| 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) | ||
| wrong_guesses_count += 1 |
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.
| wrong_guesses_count += 1 | ||
|
|
||
| print_snowman_graphic(wrong_guesses_count) | ||
| 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_word_progress_string(snowman_word, correct_letter_guess_statuses) | ||
| if is_word_guessed(snowman_word,correct_letter_guess_statuses): |
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.
| print_word_progress_string(snowman_word, correct_letter_guess_statuses) | |
| if is_word_guessed(snowman_word,correct_letter_guess_statuses): | |
| print_word_progress_string(snowman_word, correct_letter_guess_statuses) | |
| if is_word_guessed(snowman_word,correct_letter_guess_statuses): |
| print(f"Wrong guesses: {wrong_guesses_list}") | ||
| print_word_progress_string(snowman_word, correct_letter_guess_statuses) | ||
| if is_word_guessed(snowman_word,correct_letter_guess_statuses): | ||
| break |
| if is_word_guessed(snowman_word, correct_letter_guess_statuses): | ||
| print("Congratulations, you win!") |
There was a problem hiding this comment.
Nice work! You separated this logic from the while loop making it more your function overall more readable and modular. You could also have this logic inside of your while loop. What would be the disadvantages/advantages of that kind of implementation in terms of readability?
No description provided.