I am trying to write a little hangman programme and I have to use this function in it (it is explicitly said in the assignment). It should check whether the guessed letter is in the word and if so, return a word consisting of *'s and guessed letter on the right position. Yet I don`t understand how can I use the "letter" variable if it is the one the user types in (his guess), so it is practically assigned outside the function. I am stuck a bit and I would be grateful if someone would say how to do it.
def print_guessed():
global secret_word
global letters_guessed
word = []
for i in range (0, len(secret_word)):
if letter == secret_word[i]: word.append(letter)
else: word.append('-')
word_str = ''.join(word)
return word_str
NameErrorbecauseletterisn't defined anywhere.