Skip to content

Snowman PR - Bianca Caprirolo#11

Open
apradoada wants to merge 1 commit intoAdaGold:mainfrom
sausagehands:main
Open

Snowman PR - Bianca Caprirolo#11
apradoada wants to merge 1 commit intoAdaGold:mainfrom
sausagehands:main

Conversation

@apradoada
Copy link
Copy Markdown

Feedback on Snowman Submission - Bianca Caprirolo

Copy link
Copy Markdown
Author

@apradoada apradoada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Bianca!

Welcome to your first Pull Request (PR)! We will talk more about pull requests during Unit 1, but they are a great tool we have on Github to easily view and provide feedback on changes that have been made to a repository. In industry, they are often used as a way for senior developers to provide feedback to junior developers on code they have written before that code gets merged into a deployed project. Here at Ada, we use it to provide feedback on your projects! Today, I've made the PR on your behalf, but in the future, you'll make your own and submit the link to that PR instead of a link to your project.

When it comes to the feedback I give, we use a scale of Red, Yellow, Green. They mean the following:

🟢 Green 🟢: Green projects pass all the tests and your code doesn't include anything that could cause the program to behave unexpectedly. The feedback on a green project is usually more stylistic in nature or geared toward making specific pieces of code more efficient and less repetitive. You are not required to implement the feedback, but you are welcome to if you want to! However, we likely won't have time to go back and assess the changes you have made. More generally, green projects indicate that we feel you have a strong grasp of the concepts covered in the project.

🟡 Yellow 🟡: Yellow projects typically pass all of the tests provided, but do include code that may indicate uncertainty about certain concepts or how the program works as a whole. This may include code logic that causes unexpected behavior in specific situations that aren't covered in our tests. Feedback on a yellow project may be geared more toward helping you understand why a particular piece of code may fail in those circumstances. Implementing this feedback is not required, but it it highly encouraged to help you recognize patterns and implement similar solutions in the future!

🔴 Red 🔴: Red projects typically do not pass all of the tests provided. Writing code that passes all tests is an element of Test Driven Development (TDD) that is often used within the tech industry. Feedback on a red project typically includes the same type of feedback you would see on a green or yellow project along with feedback to help you understand why your code is not passing all the tests and how you could get there. If you receive a red on a project, you will be required to implement the feedback so that all tests are passing! We will then reassess when the feedback has been implemented!

As far as Snowman goes, this project is a 🟢 Green 🟢! Great Job!

The feedback I have left is just a few things to think about, but overall the logic looks good! You are welcome to implement the changes if you would like! If you have any questions about any of the feedback I have provided, feel free to reach out and I am happy to explain further.

Comment on lines -17 to -22
"""Complete the snowman function
replace "pass" below with your own code
It should print 'Congratulations, you win!'
If the player wins and,
'Sorry, you lose! The word was {snowman_word}' if the player loses
"""
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstrings are often a great way to explain what the following function does and how it operates. It is very common practice to see docstrings at the start of every function. If that is the case, no need to remove them! Go ahead and keep them in, especially if they exist in both finished and unfinished functions. This is a good indicator that the programmer intended for them to stay! In this case, instead of removing the docstring, modify it to match the work you've done on the function!

Comment on lines +22 to +25
if snowman_word == None:
snowman_word = random_word_generator.word(
word_min_length=SNOWMAN_MIN_WORD_LENGTH,
word_max_length=SNOWMAN_MAX_WORD_LENGTH)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a really cool addition to the code! Even though creating a random word is already included in the main.py, I love the way you created a default parameter!

The one thing to think about this moving forward is the full context! The snowman() function is only called once elsewhere in the program. When it is called, it always includes this code before, which means we know there will always be a valid snowman word included in the function call! With this in mind, we could remove lines 22-25 without issue.

That being said, in the context of a larger program where this function might be called in multiple different ways, this is a really good guard clause!


while len(wrong_guesses_list) < SNOWMAN_MAX_WRONG_GUESSES:

user_guess = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it comes to writing Python code, one of the guides you'll see us reference is the PEP 8 Style Guide. This is a guide for best practices when it comes to styling our code. One of the most common things we see is to try and keep individual lines of code under 79 characters. This line currently goes past that limit! It won't cause the code to break or anything, but it is a good thing to keep in mind in terms of readability and best practices!

I currently see two possible fixes here:

  1. Shorter and more concise variable names:

    • While there is no hard and fast rule on how long variable names should be, we could first try shortening the variable names we use here (correct_letter_guess_statuses and wrong_guesses_list) as they are on the longer side. That being said, these names match the parameters for the function you use to call them, which is good practice, so we'll need a different approach (but shorter variable names can help with this in other circumstances).
  2. Restyle the Function Call:

    • This is a great trick to have up your sleeve when making a function call that either includes multiple parameters or starts to approach that 79 character line limit! We can drop the parameters to the next line(s) to look something like the following:
    Suggested change
    user_guess = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list)
    user_input = get_letter_from_user(
    correct_letter_guess_statuses,
    wrong_guesses_list
    )
    • This is known as Implicit Line Continuation in Python. Whenever we have information nested inside parentheses, brackets or curly braces, we can drop the nested information to new lines without any specific notation!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @apradoada the instructions for the snowman project specified what the variable names should be & I wasn't sure if we were allowed to use our own— especially since the other functions were already defined for us. I know I could've gone through & replaced the variable names of the functions provided, but wasn't sure if that would break the tests. For future reference, would it be ok to use my own variable names? or should I stick to what's specified in the assignment instructions?


user_guess = get_letter_from_user(correct_letter_guess_statuses, wrong_guesses_list)

if user_guess in correct_letter_guess_statuses:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to highlight a really cool thing that you did here! When we receive a letter from the user, we want to check to see if the letter exists within the word or not. Given the way this program is set up, we actually end up with two different collections that hold all the letters of the word, a string (snowman_word) and a dictionary (correct_letter_guess_statuses).

While we could check either one for the letter we've received, searching within a dictionary is ever so slightly more efficient than searching through a string (We'll talk more about why in Unit 1), so great choice here!

correct_letter_guess_statuses[user_guess] = True
print_word_progress_string(
snowman_word, correct_letter_guess_statuses)
if is_word_guessed(snowman_word, correct_letter_guess_statuses):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this particular program, we have two potential finish conditions: 1. We find the word, 2. We use up all our guesses. One is a win condition and one is a lose condition.

There are a couple different ways we could handle these two conditions:

  1. Place both in a compound conditional within the while loop.
  2. Use one as the while loop conditional and nest the other conditional within the while loop.

You have opted for the latter, which I think makes sense for a few reasons:

  1. If we check both for each iteration, our loop ends if either the win or lose condition is met. This means that we are going to have to make an additional and unnecessary check after the loop to see which condition was met.
  2. If we meet one of the conditions inside the loop, we can exit the function early (which you did)! This is important because you've specifically chosen to guide your loop with the condition that has a higher threshold to meet.

One slight change you could make here would be to actually unnest this if statement. It makes sense to only check if the word has been guessed on a correct letter, but nested if statements inside a loop can start to get a little difficult to read.

snowman_word, correct_letter_guess_statuses)
if is_word_guessed(snowman_word, correct_letter_guess_statuses):
print("you win")
return
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea to use a return statement here! This will stop the function early as soon as we find the correct word. This is a great approach to use where possible!

One small tweak to make lies in the difference between an implicit and explicit return statement. If we don't include the return keyword within our function, it will return None by default. This is what would be known as an implicit return. If we include the keyword as you have done here to prematurely stop the function, we have an explicit return.

Both are valid ways to exit a function, but best practices ask us to remain consistent in which one we use within a function. While you have an explicit return here, there is technically an implicit return after line 40. The explicit return here is necessary given how you’ve organized your logic, so it would be best practice to include a return statement at the end of the function as well.


print_snowman_graphic(len(wrong_guesses_list))
print(f"wrong guesses: {wrong_guesses_list}")
print(f"sorry, you lose! the word was {snowman_word}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick, but spacing can really help with code's readability! A good rule of thumb for empty lines is to include them between distinct sections of code such as exiting a while loop or after a conditional statement!

if user_guess in correct_letter_guess_statuses:
print("You guessed a letter that's in the word!")
correct_letter_guess_statuses[user_guess] = True
print_word_progress_string(
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When organizing our logic, it can be helpful to group like lines of code together. I could see an argument for this line to be included with everything else you print out on lines 48 and 49!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants