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 trialMark Southcombe
3,361 PointsThe code does not work if there are repeating letters in the word you are guessing.
If the word has repeating letters then the good_guesses will not equal the length of the list of secret_word so it will not break.
2 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsGood observation! Secret words with repeating letters will not match lengths. This is a know issue.
In the Video Teacher's Notes, Kenneth says:
"Did you notice?
There's a tricky condition (on purpose) in the final version of our code from this video. Words that have repeated characters won't be marked as correct once they're all correctly guessed due to our len() comparisons. See if you can find a way to fix that yourself!
"
The solution would be to make a set
out of it, to compare unique letters only:
len(good_guesses) == len(set(secret_word))
>>> a = "blueberry"
>>> len(a)
9
>>> len(set(a))
6
Peter Trefren
13,898 Pointsprint out win/lose
if guess in secret_word:
good_guesses.append(guess)
done = True
for secret_letter in secret_word:
if secret_letter not in good_guesses:
done = False
if done:
print("You win! The word was {}".format(secret_word))
break
else:
bad_guesses.append(guess)
Joey B
5,275 PointsJoey B
5,275 PointsIs there any advantage to comparing the lengths to the set itself? As in,
set(good_guesses) == set(secret_word)
It seems to be working for me.