-
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
SetharikaSok_Adagrams_Atlanta #107
base: main
Are you sure you want to change the base?
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,128 @@ | ||
import random | ||
def draw_letters(): | ||
pass | ||
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 | ||
} | ||
|
||
drawn_letter = [] | ||
all_list = letters.items() | ||
mynew_list = list(all_list) | ||
|
||
while len(drawn_letter) < 10: | ||
random_number = random.randrange(0,len(mynew_list)) | ||
letter_tuples = mynew_list[random_number] | ||
key = letter_tuples[0] | ||
value = letter_tuples[1] | ||
count_key_in_list = drawn_letter.count(key) | ||
|
||
if count_key_in_list < value: | ||
drawn_letter.append(key) | ||
|
||
print(drawn_letter) | ||
return drawn_letter | ||
|
||
def uses_available_letters(word, letter_bank): | ||
pass | ||
|
||
found_count = 0 | ||
for i in letter_bank: | ||
for j in word.upper(): | ||
Comment on lines
+52
to
+53
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. Great job Rika on implementing a nested loop! This shows me that you are showing proficiency in them! An alternative way you could have implemented this is: def uses_available_letters(word, letter_bank):
cap_word = word.upper()
for letter in cap_word:
if letter not in letter_bank: return False
if cap_word.count(letter) > letter_bank.count(letter): return False
return True Python has a method for iterables called |
||
if i == j: | ||
found_count +=1 | ||
break | ||
|
||
if found_count == len(word): | ||
return True | ||
else: | ||
return False | ||
|
||
def score_word(word): | ||
pass | ||
|
||
points_dict = { | ||
'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 | ||
} | ||
|
||
count_point = 0 | ||
for key_word in word.upper(): | ||
count_point += points_dict[key_word] | ||
|
||
if len(word) in range(7, 11): | ||
count_point += 8 | ||
|
||
return count_point | ||
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. Great work on this function! Very concise and easy to follow! ⭐️ |
||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
|
||
winner_word = "" | ||
winner_score = 0 | ||
|
||
winner_dict = {} | ||
|
||
for word in word_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. One suggestion I have for you is maybe handling the determination of highest_score = 0
winning_words = []
for word in word_list:
score = score_word(word)
if score > highest_score:
highest_score = score
winning_words = [word]
elif score == highest_score:
winning_words.append(word) With this implementation we filter out words whose score is lower than the |
||
score = score_word(word) | ||
winner_dict[word] = score | ||
|
||
for word, score in winner_dict.items(): | ||
if winner_score < score: | ||
winner_score = score | ||
winner_word = word | ||
elif winner_score == score and len(word) == 10 and len(winner_word) != 10: | ||
winner_score = score | ||
winner_word = word | ||
elif winner_score == score and len(word) < len(winner_word) and len(winner_word) != 10: | ||
winner_score = score | ||
winner_word = word | ||
|
||
return (winner_word, winner_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. Great work, Rika! You are really showing some proficiency! Please feel free to contact me if you need any clarification about the comments I left! I can't wait to see more of your code in the future! 🤩 |
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.
Small comment here, so in the project description it says that certain letters should have a higher probability of being chosen than other letters. For example,
E
should have the highest probability to be chosen since theLETTER_POOL
says that there are 12 of them (line 8
). What you have onlines 33-34
don't necessarily take those weights into account. All letters have an equal chance of being chosen. A solution that considers those weights could look like this:In the beginning of the function we loop through the keys in
LETTER_POOL
to create a list with their appropriate weights.letters += 'S' * 4
-->letters = ['S', 'S', 'S', 'S']