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 trialDylan Cowling
Python Web Development Techdegree Student 2,590 PointsSlightly Confused
How does the game know where to place the correct letters along the line? I just can't figure out what I'm missing.
2 Answers
andren
28,558 PointsThe code that is responsible for printing out the secret word is this:
for letter in secret_word:
if letter in good_guesses:
print(letter, end='')
else:
print('_', end='')
It starts by looping through the secret_word
string pulling each letter into a variable called letter
, then within that loop it checks if the current letter exists within the good_guesses
list. If it is present in the list the letter is printed out, if it is not present in the list then an underscore is printed out instead.
When the game first starts the good_guesses
list is empty so all letters will be printed as underscores, once you make a guess that is correct that letter is added to good_guesses
. Which causes that letter to be printed out while the other letters which have not yet been guessed will still be printed as underscores
Chris Freeman
Treehouse Moderator 68,441 PointsGood question. In the video at 6:00 mark, Kenneth adds a for
loop to check if each letter of secret word is in the guessed letter list. If the letter has been guessed it gets printed, otherwise an underscore is printed.
Post back if you need more help. Good luck!!!
Dylan Cowling
Python Web Development Techdegree Student 2,590 PointsThank you, this helps a lot, I must have missed that part!
Dylan Cowling
Python Web Development Techdegree Student 2,590 PointsDylan Cowling
Python Web Development Techdegree Student 2,590 PointsThank you, you have made it very clear to me now. I 100% understand how it works now, success! :D