-
Notifications
You must be signed in to change notification settings - Fork 135
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
amethyst-Raina #106
base: main
Are you sure you want to change the base?
amethyst-Raina #106
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,108 @@ | ||
import random | ||
|
||
|
||
def draw_letters(): | ||
pass | ||
letter_pool = { | ||
'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 | ||
} | ||
# create list of strings 'letters' | ||
letters = [] | ||
# create empty list 'hand' | ||
hand = [] | ||
# build a random hand of 10 letters for the user | ||
while len(hand) < 10: | ||
letter_pool_keys = letter_pool.keys() | ||
letter_list = list(letter_pool_keys) | ||
if len(letter_list) > 0: | ||
letter = random.choice(letter_list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, you handled the constraints of the weights correctly (making sure that you don't have too many instances of one letter in the list). However, with letters = []
for letter in LETTER_POOL:
letters += letter * LETTER_POOL[letter] This will create a list of letters where each |
||
# Return hand that has one letter each per list item | ||
if letter_pool[letter] > 0: | ||
hand.append(letter) | ||
# subtract from letter pool | ||
letter_pool[letter] -= 1 | ||
elif letter_pool[letter] == 0: | ||
del letter_pool[letter] | ||
return hand | ||
|
||
def uses_available_letters(word, letter_bank): | ||
pass | ||
# create var to count occurrences of each letter in word | ||
word = word.upper() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One thing that we usually never want to do is reassign an argument that is passed inside of our function, so we would probably want to change this to something like |
||
word_letter_count = {} | ||
for letter in word: | ||
word_letter_count[letter] = word_letter_count.get(letter, 0) + 1 | ||
# create var to count occurrences of each letter in the letter bank | ||
bank_letter_count = {} | ||
for letter in letter_bank: | ||
# get keyname and value for each letter | ||
bank_letter_count[letter] = bank_letter_count.get(letter, 0) + 1 | ||
# compare the word_letter_count and bank_letter_count to see if word can be made | ||
for letter, count in word_letter_count.items(): | ||
# check if not in bank_letter_count | ||
if letter not in bank_letter_count or count > bank_letter_count[letter]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice use of the |
||
return False | ||
return True | ||
|
||
def score_word(word): | ||
pass | ||
letter_values = { | ||
"A": 1, "B": 3, "C": 3, "D": 2, "E": 1, "F": 4, "G": 2, "H": 4, | ||
"I": 1, "J": 8, "K": 5, "L": 1, "M": 3, "N": 1, "O": 1, "P": 3, | ||
"Q": 10, "R": 1, "S": 1, "T": 1, "U": 1, "V": 4, "W": 4, "X": 8, | ||
"Y": 4, "Z": 10 | ||
} | ||
# intialize score to 0 | ||
score = 0 | ||
# default to uppercase | ||
word = word.upper() | ||
for letter in word: | ||
# add score from letter val to overall score | ||
score += letter_values.get(letter, 0) | ||
# create if clause for words btwn len of 7 to 10 | ||
if len(word) >= 7 and len(word) <= 10: | ||
# add 8 to score var | ||
score += 8 | ||
return score | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent concise and readable function! ⭐️ |
||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
# initialize highest_score var, int | ||
highest_score = 0 | ||
# initialize winning_word var, str | ||
winning_word = "" | ||
for word in word_list: | ||
# get score for each word | ||
score = score_word(word) | ||
# find highest scoring word comp'd to previous words | ||
if score > highest_score: | ||
# designate highest score and the best word | ||
highest_score = score | ||
winning_word = word | ||
# if score is tied btwn two dif words w/ one word being 10 char long, 10 char long word wins | ||
elif score == highest_score: | ||
if (len(word) == 10 and len(winning_word) < 10) or len(word) > len(winning_word): | ||
winning_word = word | ||
# create code block for if the two highest words are less than 10 choose the shortest word | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it seems like you may of had trouble with the tie-breaking logic, it is a bit tricky! So the first thing you probably want to change its data structure you gave def get_highest_word_score(word_list):
highest_score = 0
winning_words = []
for word in word_list:
score = score_word(word)
if score > highest_score:
highest_score = score
winning_words = [word] #replacing winning)words when the score of the current word is higher than the high score
elif score == highest_score:
winning_words.append(word) #we append to winning_words when the score of said word is equal to the high score
if len(winning_words) > 1: #only applying tie-breaking logic when we have more than 1 potential winner
for word in winning_words:
if len(word) == 10: # returns the 1st 10 letter word in list
return word, highest_score # all winning words we will have the same score since they are tied.
min_word = min(winning_words, key=len) #if we make it pass the return statement we will find the shortest word based on length
winning_words = [min_word]
return winning_words[0], highest_score |
||
return (winning_word, highest_score) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job Raina and congrats on finishing your first official Ada project! Please feel free to reach out if you have any questions about the comments I left! ⭐️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could shorten this into one line by doing the following: