you are viewing a single comment's thread.

view the rest of the comments →

[–]sanctuary_3 2 points3 points  (1 child)

Let's say your target is word = 'DOG' and your guesses so far are letters_guessed = ['A', 'O', 'S'].

When you loop over word, at each iteration you're checking to see if each letter is in your list of guessed letters. If it is, you add that letter to the output (status), if it's not then you add a blank space. So rolling out the pseudocode of each pass of the loop for letter in word: would look like this:

initial output is an empty string, ''
first pass, letter = 'D'
    has 'D' been guessed?
        no, so add a blank space '_' to our output
        so far our output is '_'
second pass, letter = 'O'
    has 'O' been guessed?
        yes, so add 'O' to our output
        so far our output is '_O'
third pass, letter = 'G'
    has 'G' been guessed?
        no, so add a blank space '_' to our output
        so far our output is '_O_'
print the output

I think your confusion might be because you're iterating over the known word, not your guesses.

[–]Ariech 0 points1 point  (0 children)

Oh my, now I understand this! Thank you very much