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
Jade Jupiter
2,224 PointsPython Basics LetterGame
I was trying to recreate the lettergame, and I couldn't. My win message would only work on some words and not others. I kept on asking why and this has stumped me for days. However, today I found out why. In the course to check if you win the condition is
if len(good_guesses) == len(list(secret_word)): print("You win!") ....
however if the secret word for example is blueberry this is going to be good guesses ['b', 'l', 'u', 'e', 'r', 'y']
this is secret word
['b', 'l', 'u', 'e', 'b', 'e', 'r', 'r', 'y']
so you see if you get the word with right the length of good guesses is only going to be 6, but secret word is 8 in this case. So this only works if there are no repeation letters in the word I believe. Can anyone tell me a solution.
1 Answer
Steven Parker
243,656 Points
You could see how many letters of the word are found in good_guesses.
If that number is the same as the length of the word itself, you've won:
if len(secret_word) == len([1 for x in secret_word if x in good_guesses]): print("You win!") ...