Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Letter Game App Letter Game Introduction

Anthony Ferrero
Anthony Ferrero
2,533 Points

Understanding the concept of how these letters are getting printed.

Hi All,

I understand the challenge and completed it successfully, however, I want to better understand how this line of code works. What it does is replace the '_' with the actual letter of the word. I just don't know how the code knows how to do this, hopefully someone can enlighten me!

while len(bad) < 7 and len(good) != len(list((secret))):
    for letter in secret:
        if letter in good:
            print(letter, end='')
        else:
            print('_',end='')
    print('')
    print('Stikes: {}/7'.format(len(bad)))
    print('')
Anthony Ferrero
Anthony Ferrero
2,533 Points

Actually, I think I am getting it after review. It is a for loop. And for every letter that is in the secret word, replace it with the actual letter, if no letters are in good, replace it with '_'. Is that the concept?

1 Answer

Steven Parker
Steven Parker
231,275 Points

Your description fits the general loop mechanism. Good job! :+1: