I need to write a simple hangman function that takes in one string (the word that's being guessed) and a list of letters (the letters that are guessed). This is the code I'm using:
def WordGuessed(Word, letters):
if letters == []:
return False
else:
for i in letters:
if i not in Word:
return False
else:
if i == letters[-1]:
return True
The code usually works, but I am finding that occasionally prints the wrong answer. For example, if
WordGuessed('durian', ['h', 'a', 'c', 'd', 'i', 'm', 'n', 'r', 't', 'u'])
It prints False when it should be printing True. Can anyone see where my code is wrong?