Targeting blank spaces in string
<p>I'm creating a hangman-like game. Basically let's say I have a secret word, like, <em>"beauty and the beast"</em> and it's up to the user to guess the letters and ultimately the whole word.</p>

<p>So far my code works fine, but if you want to check it out anyway <a href="https://paste.pound-python.org/show/VGGHZNcEc2vAc5gHxOMR/" rel="nofollow">here you go</a>. Here is the relevant portion:</p>

<pre><code>def draw(good_guesses, bad_guesses, secret_word):  # DRAW spaces, letters &amp; strikes
    clear()
    print(secret_word)
    # printing strikes first
    print("Strikes: {}/7".format(len(bad_guesses)))
    print("")

    # printing bad guesses so far
    for letter in bad_guesses:
        print(letter, end=" ")  # have a space between each element
    print("\n")  # double blank lines

    # print discovered/undiscovered letters
    for letter in secret_word:
        if letter in good_guesses:
            print(letter, end=" ")
        else:
            print('_', end=" ")
    print('')
</code></pre>

<p>Back to our example though. For the string <em>"beauty and the beast"</em>, user will see printed out for him the following:</p>

<p>"_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _"</p>

<p>As you can see, the spaces of the string are printed out as underscores, and that's precisely what I'd like to change.</p>

<p>It would be much better if this was printed out instead:</p>

<p>"_ _ _ _ _ _ / _ _ _ / _ _ _ / _ _ _ _ _"</p>

<p>I'm thinking maybe there's a way to target blank spaces and print them out as spaces instead of underscores? Can't figure how to do that though.</p>

<p>Thanks.</p>

<p>In the logic of your code, you need to handle that case with an equality operator: <code>==</code>. So something like this would work:</p>

<pre><code>for letter in secret_word:
    if letter in good_guesses:
        print(letter, end=" ")
    elif letter == ' ':
        print('/', end=" ")
    else:
        print('_', end=" ")

print('')
</code></pre>

python python-3.x