title: Problems with my Hangman game (Python)
body: <p>I know this is long, please bear with me. I am taking this online class and our big project is to write code for the game Hangman. After looking online and finding some examples in order to help me get an idea of where to begin and how to go about this, I am almost done with the game. I am having just a few tiny issues that need to be cleaned up which I can't figure out how to fix. The first one deals with the spaces not lining up with the letters. So lets say the computer selects the word BASEBALL it will display <code>_ _ _ _ _ _ _ _</code> and it will seem to line up correctly. So if I guess B then it will show <code>B _ _ _ B _ _ _</code> and so on and so fourth, but as I add more and more letters, they don't line up. For instance, I will have <code>BA_EBALL _ _ _ _</code> when there is really only 1 letter left (the S). I don't know why or how it keeps adding extra blanks at the end. Another thing that I am having trouble with is repeat guesses. I programmed the game to display a message telling you to try again if you guess more than one letter or something that isn't a letter. I have a way to keep track of guessed letters, but for some reason it still allows for repeat guesses. Any help would be greatly appreciated. I apologize for this being so long and the code being longer.</p>
  
  <pre><code>import random
  hangManPics = ['''&lt;hangman art omitted&gt;''']
  
  words = 'AMERICAN NATIONAL BASEBALL BASE BALL STRIKE FOUL OUT\
   SINGLE DOUBLE TRIPLE HOMERUN PITCHER CATCHER OUTFIELD INFIELD\
   DIAMOND STADIUM CARDINALS DIAMONDBACKS BRAVES ORIOLES CUBS REDS\
   INDIANS ROCKIES TIGERS ASTROS ROYALS ANGELS DODGERS MARLINS\
   BREWER TWINS METS YANKEES ATHLETICS PHILLIES PIRATES PADRES\
   GIANTS MARINERS RAYS RANGERS NATIONALS STRIKEOUT RUNS FASTBALL\
   SLIDER CURVEBALL STEAL'
  
  ##  Select a random word from a word list
  def getRandomWord(wordList):
      newWords = words.split()    ##  split the word list
      word = newWords[random.randint(0, len(newWords) - 1)]
      return word
  
  def displayBoard(hangManPics, missedLetters, correctLetters, secretWord):
      print(hangManPics[len(missedLetters)])
      print()
  
      print("Missed letters:", end = '')
      for letter in missedLetters:
          print(letter, end = '')
      print()
  
      blanks = '_ ' * len(secretWord)
  
      for i in range(len(secretWord)):
          if secretWord[i] in correctLetters:
              blanks = blanks[:i] + secretWord[i] + blanks[i + 1:]
  
      for letter in blanks:
          print(letter, end = '')
      print()
  
  def getGuess(alreadyGuessed):
      while True:
          guess = input("Please guess a letter. ")
          upperGuess = guess.upper()
          if len(upperGuess) != 1:
              print("Please enter a single letter.\n")
          elif guess in alreadyGuessed:
              print("You have already guessed that letter. Please select another one.\n")
          elif guess not in 'abcdefghijklmnopqrstuvwxyz':
              print("Your guess must be a letter.\n")
          else:
              return upperGuess
  
  def playAgain():
      print("Would you like to play again? (yes or no)")
      return input().upper().startswith('Y')
  
  print("H A N G M A N")
  missedLetters = ''
  correctLetters = ''
  secretWord = getRandomWord(words)
  endGame = False
  
  while True:
      displayBoard(hangManPics, missedLetters, correctLetters, secretWord)
  
      guess = getGuess(missedLetters + correctLetters)
  
      if guess in secretWord:
          correctLetters = correctLetters + guess
  
          foundAllLetters = True
          for i in range(len(secretWord)):
              if secretWord[i] not in correctLetters:
                  foundAllLetters = False
                  break
          if foundAllLetters:
              print('''\&lt;ascii art omitted&gt;\n''')
              print("The secret word is", secretWord, ". You have won!\n")
              endGame = True
      else:
          missedLetters = missedLetters + guess
  
          if len(missedLetters) == len(hangManPics) - 1:
              displayBoard(hangManPics, missedLetters, correctLetters, secretWord)
              print('''&lt;ascii art omitted&gt;''')
              print("You have run out of guesses. The secret word is",\
                    secretWord, ". You lose.\n")
              endGame = True
  
      if endGame:
          if playAgain():
              missedLetters = ''
              correctLetters = ''
              endGame = False
              secretWord = getRandomWord(words)
          else:
              break
  
  playAgain()
  </code></pre>