I’m trying to code a simple text-based hang-man game, and can’t seem to get over this hump (AKA the middle portion):
while True:
from random import randint
word_list = ['elephant', 'giraffe,', 'snake', 'tiger', 'monkey', 'bird', 'leopard', 'crocodile', 'buffalo', 'mouse', 'wolf', 'pig', 'chicken', 'cheetah', 'hyena', 'shark', 'dolphin', 'lizard', 'whale', 'panda', 'gorilla']
word_choice = word_list[randint(0,20)]
word_board = [_] * (len(word_choice))
chances = 9
letter_guess = input("Enter a letter. ")
for letter_guess in word_choice:
play_again = input("Play again? Press Y or N. ")
if play_again == "Y":
continue
elif play_again == "N":
print("Ok, bye!")
break
I’m trying to find a way to get the character position of the guessed letter (letter_guess) in the given word (word_choice), and have that letter replace the appropriate dash position in the ‘word_board’ list. I was able to look up the index() and find() methods, but to my understanding, these only return the first instance.