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 trialDiwakar Singh
Courses Plus Student 1,621 Pointswhat is wrong with my code
import random
words = ['apples', 'banana', 'grapes', 'orange', 'lemon', 'melon', 'strawberry']
while True: start = input("Press enter/return to play or q to quit ") if start.lower() == 'q': break
secret_word = random.choice(words)
good_guesses = []
bad_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('_', end='')
print('')
print("strikes : {}/7".format(len(bad_guesses))
print('')
guess = input("guess a letter :").lower()
if len(guess) != 1:
print("you can guess only single letters ")
continue
elif guess in bad_guesses or guess in good_guesses:
print("you already guessd that letter ")
continue
elif not guess.isaplha():
print("you can only guess alhabets ")
continue
if guess in secret_word:
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)
else:
print("you lose my word was {} ".format(secret_word))
1 Answer
Toni Swats
3,447 Points``` print("strikes : {}/7".format(len(bad_guesses))
is missing a closing parenthesis.
I know you're probably asking more about the function of the code, but if you fix that syntax error your REPL will show you more specific errors related to your actual code function. Also, it looks like your markdown is broken because it's breaking mine ^^