title: Python - Hangman
body: <p>I just wrote a functioning program to play Hangman game, but there's one issue that's bothering me which I haven't been able to figure out.</p>
  
  <p>The program correctly asseses whether the chosen character is in the word to be guessed, as well as its position in the word (even if the character appears more than once). Nonetheless, when playing the game it takes one more turn than needed to asses whether you guessed the word completely, or whether you have no lifes left.</p>
  
  <p>Say, for example, you have to guess the word 'hello'. I would expect to program to run like:</p>
  
  <p>Turn 1: 'h'. Turn 2: 'e'. Turn 3: 'l'. Turn 4: 'o'. The program should stop here, but it needs another character (any) to recognize that the game has been completed.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>def play_game():
  
      # Pick word randomly from list
      random_num = random.randint(0, (len(words_list) - 1))
      current_word = list(words_list[random_num].upper())
      print(current_word)
      print('The word has', str(len(current_word)), 'characters')
  
      current_letter = input('Pick a letter: ').upper() #User input
      picked_letters = []
      correct_ones = []
      for i in range(len(current_word)):
          correct_ones.append('_ ')
  
      lifes = 3
      while lifes != 0:
  
          # Check if all characters have been already guessed
          if current_word == correct_ones:
              print('You won!')
              break
  
          # Check if character has already been chosen
          elif current_letter in picked_letters:
              print('You already chose this letter!')
              current_letter = input('Pick another letter: ').upper()
              continue
  
          # Check if character is in word
          if current_letter in current_word:
              index_list = []
              for i in range(len(current_word)): #Get indexes of character in word
                  if current_word[i] == current_letter:
                      index_list.append(i)
  
              picked_letters.append(current_letter) #Append to keep track of chosen characters         
              for i in index_list:
                  correct_ones[i] = current_letter.upper() #Append to correct position
  
              print('Correct!')
              for i in correct_ones:
                  print(i + ' ', end='')
              current_letter = input('Pick another letter: ').upper()
  
          # Incorrect character
          else:
              picked_letters.append(current_letter)
              lifes -= 1
              print('Incorrect')
              print('You have', str(lifes), 'lifes left')
              current_letter = input('Pick another letter: ').upper()
              continue
  
  
  play_game()
  </code></pre>
  
  <p>If you see any bad practice in my code feel free to tell me so!</p>
  
  <p>Thanks in advance!</p>