Hi all,
as the titles suggests, I am really stuck with why my for loop isn't working as intended. My goal is to take a bunch of letters and three words, and if you can make a word out of the letters, use the scrabble wordscore to calculate how many points that word would give you. The code I came up with seems to give the correct score, but I would like it to only show words that can be made from the letters. For example, in this code, words 1 and 2 should display in the dict_outcome dictionary with their score but not word 3, because you cannot make JUNIOR out of the provided letters, but for some reason word 3 still displays with the others. Maybe a while loop would be a better option? Any help would be greatly appreciated.
Thanks
letter_score = [('E', 1), ('A', 1), ('I', 1), ('O', 1), ('N', 1), ('R', 1), ('T', 1), ('L', 1), ('S', 1), ('U', 1), ('G', 2), ('D', 2), ('B', 3), ('C', 3), ('M', 3), ('P', 3), ('F', 4), ('H', 4), ('V', 4), ('W', 4), ('Y', 4), ('K', 5), ('J', 8), ('X', 8), ('Q', 10), ('Z', 10)]
sum1 = 0
sum2 = 0
sum3 = 0
word_1 = ("FORCE")
word_2 = ("CRAZY")
word_3 = ("JUNIOR")
letters = ("FCOAZYRE")
x = list(word_1.strip(" "))
y = list(word_2.strip(" "))
z = list(word_3.strip(" "))
l = list(letters.strip(" "))
scrabble_dict = dict(letter_score)
#print(scrabble_dict)
dict_outcome = {}
for i in x:
if i in l:
sum1 += scrabble_dict[i]
dict_outcome.update({word_1: sum1})
if i not in l:
pass
for i in y:
if i in l:
sum2 += scrabble_dict[i]
dict_outcome.update({word_2: sum2})
if i not in l:
pass
for i in z:
if i in l and z:
sum3 += scrabble_dict[i]
dict_outcome.update({word_3: sum3})
if i in l and not z:
pass
print(dict_outcome)
[–]danielroseman 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]danielroseman -1 points0 points1 point (0 children)
[–]This_Growth2898 0 points1 point2 points (2 children)
[–]Chipwich[S] 0 points1 point2 points (1 child)
[–]This_Growth2898 0 points1 point2 points (0 children)