There is a list with words (wordListReal). Every letter in the alphabet has an assigned value (see code).
Now the question is how to obtain the value of all the letter values added together per word, then divided by the number of letters in that word.
I tried this, but strangely enough it returns only lots of 0, 1 and 2, which is incorrect:
# wordListReal = ["mystery", "strange", "why", "how", "thinking", "solution", "gratitude", "life"]
frequencyPointList = []
points1 = 0
points2 = 0
for word1 in wordListReal:
points1 = 0
for letter1 in word1:
if letter1 in {"e" , "a" , "r" , "i" , "o"}:
points1 += 1
elif letter1 in {"t" , "n" , "s" , "l" , "c"}:
points1 += 2
elif letter1 in {"u" , "d" , "p" , "m" , "h"}:
points1 += 3
elif letter1 in {"g" , "b" , "f" , "y" , "w"}:
points1 += 4
elif letter1 in {"k" , "v" , "x" , "z" , "j" , "q"}:
points1 += 5
numberLetters1 = len(word1)
points2 = points1 // numberLetters1
frequencyPointList.append(points2)
print(frequencyPointList)
Eventually the results need to be in a list, not in a dictionary.
Many thanks in advance!
Edit: through in between printing it becomes more clear where the problem lies, but not how to solve it yet. Points1 and numberLetters1 are calculated correctly and they are both integers, but when dividing them through each other to arrive at points2 something goes wrong!
wordListReal = ["mystery", "strange", "why", "how", "thinking", "solution", "gratitude", "life"]
frequencyPointList = []
points1 = 0
points2 = 0
for word1 in wordListReal:
points1 = 0
for letter1 in word1:
if letter1 in {"e" , "a" , "r" , "i" , "o"}:
points1 += 1
elif letter1 in {"t" , "n" , "s" , "l" , "c"}:
points1 += 2
elif letter1 in {"u" , "d" , "p" , "m" , "h"}:
points1 += 3
elif letter1 in {"g" , "b" , "f" , "y" , "w"}:
points1 += 4
elif letter1 in {"k" , "v" , "x" , "z" , "j" , "q"}:
points1 += 5
print("points1: " + str(points1))
print(type(points1))
numberLetters1 = len(word1)
print("numberLetters1: " + str(numberLetters1))
print(type(numberLetters1))
points2 = (int(points1) // int(numberLetters1))
print("points2: " + str(points2))
print(type(points2))
frequencyPointList.append(points2)