Python: Using a variable inside a function (but the variable should be users input) -


i trying write little hangman programme , have use function in (it explicitly said in assignment). should check whether guessed letter in word , if so, return word consisting of *'s , guessed letter on right position. yet don`t understand how can use "letter" variable if 1 user types in (his guess), practically assigned outside function. stuck bit , grateful if how it.

def print_guessed():     global secret_word     global letters_guessed     word = []     in range (0, len(secret_word)):         if letter == secret_word[i]: word.append(letter)         else: word.append('-')     word_str = ''.join(word)     return word_str 

i f can make change function, modify argument it, variable-letter.

def print_guessed(letter):     #do_stuff 

and supply letter guessed in call statement

print_guessed(letter) 

Comments