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 trialRastko Jovic
14,883 PointsWhen first letter is uppercase it doesn't get inserted into REVEALED?
while True:
choice = input("What letter are you looking for?>> ")
if choice.isalpha() and len(choice) == 1 and choice not in good_guesses + bad_guesses:
break
else:
print("Choose another letter")
# Check if CHOICE in WORD
if choice in word:
#Find all occurrences of choice and put it in revealed
for position in range(0, len(word)):
if word[position].lower() == choice:
revealed[position] = choice
# Put CHOICE in GOOD_GUESSES
good_guesses.append(choice)
else:
# Put CHOICE in BAD_GUESSES
bad_guesses.append(choice)
print(revealed)
if '-' not in revealed:
print("YOU WON!")
return
else:
print("Game over, the correct word was: {}".format(word))
For some reason when i try to match the lowercase version of the letter in WORD to the CHOICE it does match it but doesn't insert it into revealed?
1 Answer
Iain Simmons
Treehouse Moderator 32,305 PointsYou're only checking for the lowercase version of the letter from the word
, not the choice
or anywhere else.
Unless you want to have to convert everything to lowercase when comparing or checking if something exists in an array, I'd suggest converting choice
to lowercase as soon as you get it from input
, and converting word
to lower case before you check it at all:
word = "Supercalifragilisticexpialidocious".lower()
choice = input("What letter are you looking for?>> ").lower()