When referencing against a functions return. The len() of the return is skewed based off of formatting the output for readability. Example below.
Function definition
def get_guessed_word(secret_word, letters_guessed):
'''
secret_word: string, the word the user is guessing
letters_guessed: list (of letters), which letters have been guessed so far
returns: string, comprised of letters, underscores (_), and spaces that represents
which letters in secret_word have been guessed so far.
'''
# FILL IN YOUR CODE HERE AND DELETE "pass"
correct_guess = []
for e in secret_word:
if e in letters_guessed:
correct_guess.append(e)
else:
correct_guess.append('_ ')
return(''.join(correct_guess))
Function Call
else:
print("Available Letters:", (get_available_letters(letters_guessed)))
print(get_guessed_word(secret_word, letters_guessed))
print(len(get_guessed_word(secret_word, letters_guessed)))
print("Good Guess!")
print("You have", num_guesses,"guesses left.")
The line print(len(get_guessed_word(secret_word, letters_guessed))) was for me to check where my len() operation was being skewed and it is here (Listed in the output below).
Output/Issue when using the return from the defined function for checking len() against…
Enter Guess: a
Available Letters: b c d e f g h i j k l m n o p q r s t u v w x y z
**a_ _ _ _ **
9
Good Guess!
You have 6 guesses left.
Apple is only a 5 letter word but based off my formatting '_ ’ for readability in the function definition, it is skewing any attempts at cross referencing another list of words against my return from this function. I do want the spaces there on the output. But I need to have len(A______) as it really is (5 letters) to reference against in a later function. Docstring for the later function listed below.
Functions I intend to use this return for.
def match_with_gaps(my_word, other_word):
'''
my_word: string with _ characters, current guess of secret word
other_word: string, regular English word
returns: boolean, True if all the actual letters of my_word match the
corresponding letters of other_word, or the letter is the special symbol
_ , and my_word and other_word are of the same length;
False otherwise:
'''
# FILL IN YOUR CODE HERE AND DELETE "pass"
for word in wordlist:
if len(word) == len(get_guessed_word(secret_word, letters_guessed)):
other_word.append(word)
def show_possible_matches(my_word):
'''
my_word: string with _ characters, current guess of secret word
returns: nothing, but should print out every word in wordlist that matches my_word
Keep in mind that in hangman when a letter is guessed, all the positions
at which that letter occurs in the secret word are revealed.
Therefore, the hidden letter(_ ) cannot be one of the letters in the word
that has already been revealed.
'''
Seems like such a silly issue to have and I hope I have conveyed the issue I am having clearly enough for someone to help! Thanks in advance for any advice!