If you use exception testing, you can handle guess being incorrect:
word = 'word' spaces = list('-' * len(word)) guess = 'o' try: locate = word.index(guess) spaces[locate] = guess print(f"{spaces}") except ValueError: print(f"guess {guess} not in word")output:
Output:['-', 'o', '-', '-']
you can put it all in a function to complete