I'm building a 'scrabble' game in Python. Basically, the user is given 7 randomly generated letters and these are stored in the list random_letters
. They then enter a word using those letters - this is a string stored as player1_word
.
The bit I am stuck on is where I need to validate that the user has entered a valid word - e.g is player1_word
only using letters from random_letters
.
def is_valid_answer(player_word: str, letters: list) -> bool:
...
Expected behaviour:
>>> random_letters = ["D", "O", "G", "P", "X", "K"]
>>> is_valid_answer("DOG", random_letters)
True
>>> is_valid_answer("CAT", random_letters)
False