title: Getting a confusing TypeError. Mastermind game
body: <p>I have finished creating the MasterMind game, but I am getting a TypeError that I am not able to debug. It does say what I am doing wrong on the error, but do not know how to fix this.
  This is my code:</p>
  <pre><code>import random
  letters = [&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;F&quot;]
  length = 4
  
  def main():
    list_code = create_code(4)
    secret_code = &quot;&quot;.join(list_code)
  
    guess_counter = 0
    guess = &quot;&quot;
    list_guess = &quot;&quot;
    while guess_counter &lt; 10 and guess != secret_code:
      list_guess = get_code()
      guess = &quot;&quot;.join(list_guess)
      result = check_code(secret_code, guess)
      guess_counter+= 1
    
  
    if guess == secret_code:
      print(&quot;You win!&quot;)
    else:
      print(&quot;Sorry, you lost. The corect code was&quot;, secret_code)
  
  
  def create_code(length):
    letters_copy = letters.copy()
    code_word = &quot;&quot;
    for i in range(length):
      letter = random.choice(letters_copy)
      letters_copy.remove(letter)
      code_word = code_word + letter
    code = list(code_word)
    return code
  
  def get_code():
    guess_code = input(&quot;Guess the 4 digit code (abcd): &quot;).upper()
    user_code = list(guess_code)
    if len(user_code) != length:
      print(&quot;Must enter only 4 letters&quot;)
      user_code = get_code()
    for i in guess_code:
      if user_code[i] in letters: 
        continue
      else:
        print(&quot;invalid answer, choose between letters a, b, c, d, e, f&quot;)
        user_code = guess_code()
        break
    return guess_code
  
  
  def check_code(secret_code, guess):
    white_counter = 0
    red_counter = 0
    win = False
    for i in guess:
      if guess[i] in secret_code[i]:
        red_counter += 1
        continue
      elif guess[i] in secret_code:
        white_counter += 1
        continue
      else:
        continue
    print(&quot;R&quot;*red_counter, &quot;W&quot;*white_counter)
    return white_counter, red_counter
  
  
  main()
  
  </code></pre>
  <p>And the error I am getting when I run this program is:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;main.py&quot;, line 71, in &lt;module&gt;
      main()
    File &quot;main.py&quot;, line 13, in main
      list_guess = get_code()
    File &quot;main.py&quot;, line 42, in get_code
      if user_code[i] in letters: 
  TypeError: list indices must be integers or slices, not str
  </code></pre>
  <p>I don't know what I am doing wrong so any help would be great.
  Thank you!</p>