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 trialIdan shami
13,251 PointsProblem in letter game + I want to add something
Hi ! my name is Idan and I just watched the video about the letter game, but I didn't set the same words as Kenneth set, in my words, there are some spaces because I decided to set TV shows as my words, but the problem is that Python include the spaces in the word, and when I adding a space the program tells me " you can only guess letters! " because of that line we wrote in the video:
elif not guess.isalpha():
is there any way that I can tell python to not include the spaces? (i am sure there is...) and the second question I have is about a problem that is happening to me, and I don't know how to fix it.... when the program decides that the secret word will be the series ' glee ' even if I guess the word when I am writing ' e ' it's adding the ' e ' 2 times and not finishing the game....... here is my code:
import random
# make a list of words
words = [
'big bang theory',
'family guy',
'rick and morty',
'american dad',
'modern family',
'how do I met you mother',
'two and a half man',
'glee',
'icarly',
'drake and josh',
'good luck charlie'
]
while True:
start = input("Press enter to start or Q to quit ")
if start.lower() == 'q':
break
# pick a random word
secret_word = random.choice(words)
bad_guesses = []
good_guesses = []
while len(bad_guesses) < 7 and len(good_guesses) != len(list(secret_word)):
# draw guesses letters,spaces, and strikes
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('')
# take a guess
guess = input("Guess a letter: ").lower()
if len(guess) != 1:
print("You can only take 1 letter!")
continue
elif guess in bad_guesses or guess in good_guesses:
print("you've already guessed that letter!")
continue
elif not guess.isalpha():
print("you can only guess letters!")
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 didn't guesses it! my secret word was {}".format(secret_word))
how to solve it ? sorry for my bad English. thanks Idan ^-^