Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lions - Nancy L. #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Lions - Nancy L. #82

wants to merge 3 commits into from

Conversation

nancy-lee89
Copy link

This is my individual project as requested by Auberon. I was unable to collaborate in writing code with my partner so I started my own to practice.

Copy link

@alope107 alope107 left a comment

Choose a reason for hiding this comment

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

Thanks for giving this another look! There are still some logic problems remaining, but I really like the ideas behind your code.

Comment on lines +5 to +15
available_letters = {
"A": 9, "B": 2, "C": 2,
"D" : 4, "E": 12, "F": 2,
"G": 3, "H": 2, "I": 9,
"J": 1, "K": 1, "L":4,
"M": 2, "N": 6, "O": 8,
"P": 2, "Q": 1, "R": 6,
"S": 4, "T": 6, "U": 4,
"V": 2, "W":2, "X": 1,
"Y": 2, "Z": 1
}

Choose a reason for hiding this comment

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

Smart to include dictionary here!

Comment on lines +20 to +28
for _ in range(10):
letters = []
for letter, quantity in available_letters.items():
for _ in range(quantity):
letters.append(letter)

selection = random.choice(letters)
hand_available.append(selection)
available_letters[selection] = available_letters[selection] - 1

Choose a reason for hiding this comment

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

This works well! Nice use of a list of all the available letters to make random.choice work.

Comment on lines +31 to +43
# iterate through the length of dictionary of letters/quantity available (key:value)
for letter, quantity in available_letters.items():
# # randomly choose a letter in the dictionary using keys
# selection = random.choice(list(available_letters.keys()) -I was unable to get this to work in the loop-
selection = random.choice(letter)
# if the user list has < 10 letters
if len(hand_available) < 10:
# # if the quantity of the letter is not 0 (value)
if quantity != 0:
# # add the letter to the empty list
hand_available.append(selection)
# # subtract that number from the amounts available
quantity -= 1

Choose a reason for hiding this comment

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

I like the idea here, but it unfortunately doesn't quite work. Here we're looking at the letters one at a time in the order they appeared in the dictionary. Because we're just looking at one letter at a time, random.choice doesn't actually choose anything randomly - it will just choose the one letter that we're looking at.

Comment on lines 48 to +53
def uses_available_letters(word, letter_bank):
pass
for letter in word:
if letter in letter_bank:
return True
elif letter not in letter_bank or len(word) > len(letter_bank):
return False

Choose a reason for hiding this comment

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

This is on the right track! There are two main issues:

  • It can return too early. If the first letter is in the letter bank, it will immediately return True, without considering whether any of the other letters match. This is because the return statement on line 51 immediately ends our function, not letting the rest of the loop run.
  • It doesn't consider duplicate letters. If our word has two As, but the letter bank only allows one, line 52 will not properly catch that we've used a letter too many times.

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