I have a question for one of my assignments.
Inside the file “scrabble.py”, create a program which:
- Asks the user for a word (assume the word is in lowercase)
- Each character in the word must be found in the letters list above. If it is not, ask the user for a new input until a valid word is given
- Print out the score achieved by adding the number of points associated to each letter in that word
- You should not use any string methods (if you are aware of them), such as .index, etc.
My solution:
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]
new = [ ]
word = input("type a word (in lower case): ")
for elm in word:
if elm in letters:
idx = letters.index(elm)
new.append(points[idx])
continue
if elm not in letters:
print("Key in a proper word!")
word = input("type a word (in lower case): ")
print(new)
Sum_of_points = sum(new)
print(f"The total points is: {Sum_of_points}")
The issue I am facing is that after the user inputs the wrong figure at the start, it will prompt the user again, but however it will not repeat the loop from the very beginning. I would like it to repeat the loop, how should I go about doing this? I would greatly appreciate feedback on how to improve this too!