I have a problem with contiunation of the loop. Here is a code of the hangman for Python. Although using the list or just print for each character seem to be easier ways to proceed the task, I would like to know, where is the problem of the presented solution in order to avoid the future troubles.
word='heksakosjokontaheksafobia'
def hangman(input, word_to_guess):
users_guess=input('What is the first letter of your first thought?\n')
print (users_guess)
if users_guess in word_to_guess:
unknown_chararcters='*'*len(word_to_guess) # The creation of a string showing number of uknown characters
print(unknown_characters)
for char in word_to_guess:
if char==users_guess: # Checking whether input is included in word_to_guess
ind=word_to_guess.index(char)
unknown_characters=unknown_characters[:ind]+users_guess+unknown_characters[ind+1:] # Substitution of '*' with input
continue
print(unknown_characters)
hangman(input, word)
As you can see, the word includes many 'a', however for input==a the output is:
What is the first letter of your first thought?
a
*************************
****a********************
How can I force the loop to iterate over the following characters of a string?