I have a person calling a function with three inputs:
puzzle- so a random word, for example. 'john'view- their view of the puzzle (they guess letters and they become revealed scoring points, etc) so lets say they only seej^h^(^ represents hidden characters).letter_guessed- they guess a letter, so if someone guessed'o', the view would come back as'joh^'
But my code just doesn't seem work and I can't seem to understand why, and please if you could do it using my bit of code below, I understand there are many ways to solve it but I'm interested in what I had to do if I wanted to solve this question using a for statement with nested if statements.
What it doesnt do: it simply displays the view again, the line of incorrect code is result = result + letter because i dont know how to make python scan for the hidden variable and replace the ^ with set found alphabetic letter.
def update_view(puzzle,view,letter_guessed):
result = ""
for index in range(0,len(puzzle)):
if puzzle[index] == letter_guessed:
result = result + letter_guessed
else:
result = view
return result
/usr/share/dict/wordsto pick a word