Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why doesnt my Python function print to console?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading