pyTony
pyMod
5,359 posts since Apr 2010
Reputation Points: 782
Solved Threads: 852
And what happens when they guess "books" and it is "bones". You have to eliminate a letter that is found or it will "find" two o's when there is only one. Since we don't know what kind of containers realWord and guess are, I am using a list since they are easier to work with.
real_word = "books"
for guess in ["bones", "good", "bookkeeper"]:
print "\n testing", guess
if guess != real_word:
## list of "_" to be updated with letters found in both words
guess_list = ["_" for x in range(len(real_word))]
real_list = list(real_word.lower())
for char in guess:
if char in real_list:
offset = real_list.index(char) ## offset position of the found letter
guess_list[offset] = char ## update with correct letters
real_list[offset] = "*" ## letter found so don't test it again
else:
print(char)# If not in word print letter alone
print guess_list
print real_list, "= real_list" ## for testing
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714