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 Kohner
1,760 Pointsletter game exits on first correct guess?
I found this video extremely confusing and lacking the depth of the previous ones, there is not much explanation to the function arguments or the reasoning behind the arrangements, how to use "Found" and "done", which is I think the cause of my issue but I cannot find a fix.
Everything seems to be working correctly, except the first guess registers as a win and exits the game. I can't properly post the code, it is getting split into a mix of plain text, utf, and properly formatted code. I will try a snippet
def play(done):
clear()
secret_word = random.choice(words)
bad_guesses = []
good_guesses = []
while True:
draw(bad_guesses, good_guesses, secret_word)
guess = get_guess(bad_guesses, good_guesses)
if guess in secret_word:
good_guesses.append(guess)
found = True
for letter in secret_word:
if letter not in good_guesses:
found = False
if found:
print("you win!")
print("secret word was {}".format(secret_word))
done = True
else:
bad_guesses.append(guess)
if len(bad_guesses) == 7:
draw(bad_guesses, good_guesses, secret_word)
print("You lost. sorry.")
print("Secret word was : {}".format(secret_word))
done = True
if done:
play_again = input("play again? Y/n").lower()
if play_again != 'n':
return play(done=False)
else:
sys.exit()
1 Answer
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsPost all code to check. Posting Code: Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.
Vittorio Somaschini
33,371 PointsVittorio Somaschini
33,371 PointsHello Mark.
I have edited your question, code looks fine now. Please have a read here: https://teamtreehouse.com/forum/posting-code-to-the-forum
;) Vitto