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 trialBartłomiej Kuczma
903 PointsOne mistake in this game, which does not end the game with word "BANANA"
I've tried letter "A" so it shown me _A_A_A , my next quess was B, so obv. BA_A_A, but after that i put in "N" and it says
Guess a letter: n banana Strikes: 6/7
Tried to type "N" again but "Guess a letter: n You've already guessed that letter! banana "
We should fix that problem ;)
3 Answers
Steven Parker
231,269 PointsYou might need different logic for detecting a win.
If you're comparing the total number of correct guesses against the length of the word, the program will work for words where all letters are unique (like "branch"), but it will never think you have completed the game when the word has repeated letters (like "banana").
You probably need to revise your logic for detecting a win. You could do something like testing to see if every letter of the word is in the list of correct guesses, for example.
Vera Dou
1,532 PointsI replaced line 53-59 with the code below and it worked for any word. The for loop compares each letter in a word with the guess in turn and pushes every match into the good_guesses array so the length of the good_guesses array always reflects the number of all letters (including multiple occurrences) that have been figured. In case that the secret word is "banana" and the guess is "n", "n" would be added to good_guesses twice.
if guess in secret_word:
for letter in secret_word:
if guess == letter:
good_guesses.append(guess)
if len(good_guesses) == len(list(secret_word)):
print("You win! The word was {}".format(secret_word))
break
else:
bad_guesses.append(guess)
Chris Freeman
Treehouse Moderator 68,441 PointsYou can not simply compare the length of guesses (known to be unique) with the length of the target word (repeated letters may exist). Hint: One way to find out the length of unique characters in a word is the "length of a set
made from the word"
Torsten Lundahl
2,570 PointsTorsten Lundahl
2,570 PointsIt's impossible to tell what's causing the problem without any form of code. If you want help you have to give a better explanation and elaborate on the problem.