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 trialJonathan Whelchel
2,096 PointsTrouble with numbers game
My code isn't saving bad guesses correctly. the badd_guesses list will add the first bad guess bit any other bad guess after that, it says I already guess that letter.
import random
words = [
'orange'
]
while True:
start = input("Press return/enter to start, Q to quit")
if start.lower() == 'q':
break
secret_word = random.choice(words)
bad_guesses = []
good_guesses = []
while len(bad_guesses) < 7 and len (good_guesses) != len(list(secret_word)):
for letter in secret_word:
if letter in good_guesses:
print(letter, end='')
else:
print('_')
print('')
print('Strike: {}/7'.format(len(bad_guesses)))
print('')
guess = input("Guess a letter. ").lower()
if len(guess) != 1:
print('You can only guess one letter!')
continue
elif guess in good_guesses or bad_guesses:
print("You've already guessed that letter!")
continue
if guess in secret_word:
good_guesses.append(guess)
if len(good_guesses) == len(list(secret_word)):
print("You win! My word was {}".format(secret_word))
break
if guess not in secret_word:
bad_guesses.append(guess)
continue
1 Answer
Lukas Baumgartner
14,817 Pointselif guess in good_guesses or bad_guesses:
print("You've already guessed that letter!")
continue
Take a look again at this. Something isn't right here.
Your or statement syntax is not okay. You wrote it as you would say it out loud, but python isn't that smart to make connections in a sentence. So try to tell it exactly what you want :)
Let me know if there is something else i can help you with!
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 Pointsmoved to answer.