Skip to content

Sphinx - Vlada Rapaport#31

Open
vladarap88 wants to merge 1 commit into
Ada-C22:mainfrom
vladarap88:main
Open

Sphinx - Vlada Rapaport#31
vladarap88 wants to merge 1 commit into
Ada-C22:mainfrom
vladarap88:main

Conversation

@vladarap88

Copy link
Copy Markdown

No description provided.

@yangashley yangashley left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great job on Adagrams!

In the future, consider making a commit after finishing each wave.

Let me know if you have questions about my comments!

Comment thread adagrams/game.py
@@ -1,11 +1,145 @@

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Delete unneeded blank line

You can review the official Python style guide about blank line conventions.

Comment thread adagrams/game.py

def draw_letters():
pass
letter_pool = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

letter_pool is a constant variable and should be named with capital letters like LETTER_POOL

Comment thread adagrams/game.py
Comment on lines +33 to +35
letters = ""
for letter , num in letter_pool.items():
letters += letter * num

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your implementation of draw_letters has 2 responsibilities: creating a pool of letters and also drawing random letters. Consider putting the logic on lines 33-35 into a helper function (maybe something like build_letter_pool and call that function here instead.

Comment thread adagrams/game.py
for letter , num in letter_pool.items():
letters += letter * num

result = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The name result doesn't quite capture what this list represent in the game. Something like randomly_hand describes that this list is a random hand in the game which would make your code more self-documenting.

Comment thread adagrams/game.py
}

while len(result) < 10:
i = random.randint(0, len(letters) - 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What does i represent? Something like random_index would be more descriptive.

Comment thread adagrams/game.py
Comment on lines +121 to +122
if len(word) >=7 and len(word) <= 10:
sum_word += 8

@yangashley yangashley Sep 23, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using constant variables will make your code more self-documenting and easier to understand. If I don't know anything about this game, I'm left wondering what the significance of the integer literals 7, 10, and 8 are.

Consider something like:

BONUS_LENGTH_MIN = 7
BONUS_LENGTH_MAX = 10
BONUS_POINTS = 8

if BONUS_LENGTH_MIN <= len(word) <= BONUS_LENGTH_MAX:
        sum_word += BONUS_POINTS

Comment thread adagrams/game.py
'Z': 0
}

while len(result) < 10:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'd like to see the literal integer 10 referenced by a constant variable. As someone who might not know anything about this game, I might read line67 and wonder what the significance of 10 means.

How about something like:

HAND_SIZE = 10
while len(result) < HAND_SIZE:

Comment thread adagrams/game.py
Comment on lines +142 to +145




Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Delete blank lines at end of file to keep project neat. Python recommends you keep one blank line so you can remove lines 143-145

You can check out this thread to read more if you'd like

Comment thread adagrams/game.py
max_score = score
max_word = word
elif score == max_score and (len(word) != len(max_word)):
if len(word) == 10:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We could use a constant variable to reference 10, maybe something like TIE_BREAKER_LENGTH or something else to describe why 10 is significant in this logic.

Comment thread adagrams/game.py
elif len(word) < len(max_word) and len(max_word) != 10:
max_word = word

return (max_word, max_score)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Nice job directly returning the tuple

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