I can't seem to figure out why my function doesn't print anything when called.
This is the function (and a list that's used in the function):
old_letters = ['a', 'p', 'c', 'f']
def try_update_letter_guessed(letter_guessed, old_letters_guessed):
length = len(letter_guessed)
english_validation = letter_guessed.isalpha()
already_used = letter_guessed in old_letters_guessed
if (length > 1) or (english_validation == False) or (already_used == True):
print("X")
delim = "->"
res = delim.join(sorted(old_letters_guessed))
print(res)
return False
elif (length == 1) and (english_validation == True) and (already_used == False):
old_letters_guessed.append(letter_guessed)
return True
However, when I call my function (with arguments) like so:
try_update_letter_guessed('A', old_letters)
it doesn't print anything at all.
What am I missing?
CodePudding user response:
When letter_guessed
is 'A'
, then (length > 1) or (english_validation == False) or (already_used == True)
is not true, so this goes to the elif, and that doesn't print anything.
If you try with arguments which will make that condition true, then it does print:
>>> try_update_letter_guessed('AB', old_letters)
X
A->a->c->f->p
False
>>> try_update_letter_guessed('a', old_letters)
X
A->a->c->f->p
False
CodePudding user response:
Of course, use print() inside the elif block. because the argument 'A' will only lead into the elif block so after appending to the old_letters_guessed if you wanna see something on console use the function print()