I am writing a simple program for a homework problem and It seems to be skipping my if statement. I have looked at other questions posed, and the problems there do not seem to b
The other answers explain the error in the code well, but you can simplify your code a bit like this:
def isWordGuessed(secretWord, lettersGuessed):
for i in lettersGuessed or ['_']: # uses ['_'] when lettersGuessed = []
if not i in secretWord:
return False
return True
You can do also do this with a generator expression and all()
:
def isWordGuessed(secretWord, lettersGuessed):
return all([i in secretWord for i in lettersGuessed] or [False])