title: Mastermind Python problem for correct colour and correct place and correct colour and wrong place
body: <p>Hi Below is my master mind game python code, now I have a problem that example: when the answer is &quot;RGRG&quot; and I enter the alphabet &quot;GRRG&quot; by right the output for Correct colour and correct place should be = 2 and Correct colour and wrong place should be = 2. but now the output is wrong and it shows that colour and correct place = 2 but Correct colour and wrong place = 0. So if anybody know what part of my code is wrong?</p>
  <pre><code>import random
  from random import choice
  
  print(&quot;Welcome to Chee Fung Mastermind Games&quot;)
  opening = input(&quot;Hi Do you need instruction or starightly enter into the game. [I/G]\n&quot;)
  if opening == &quot;I&quot; or opening == &quot;i&quot; :
          print(&quot;Computer will automatically generate four colour from list.&quot;)
          print(&quot;Player must guess 4 colours numbers correct from the list to win the game.&quot;)
          print(&quot;You have 10 times chances to atempt the game.&quot;)
          print(&quot;There will be 5 colours in the below list.&quot;)
          print(&quot;(R)Red, (G)Green, (B)Blue, (P)Purple, (O)Orange&quot;)
          print(&quot;Player no need to enter the whole word, just need to enter the first alphabetical of the colours.&quot;)
          print(&quot;Example: for Red colour you just need to enter 'r' or 'R'.&quot;)
  else:
          print(&quot;Let's start the game.&quot;)
  prev_curt_color = 0
  colors = [&quot;R&quot;, &quot;G&quot;, &quot;B&quot;, &quot;Y&quot;, &quot;W&quot;, &quot;P&quot;]
  attempts = 0
  game = True
  
  # computer randomly picks four-color code
  color_code = []
  for i in range(4):
          color_code.append(choice(colors))
  print (color_code)
  
  
  # player guesses the number
  while game:
          correct_color = 0
          guessed_color = 0
          player_guess = input(&quot;Please enter the four colour:&quot;).upper()
          attempts += 1
          # checking if player's input is correct
          if len(player_guess) != len(color_code):
                  print (&quot;\nThe color code has exactly four colors. please try again!&quot;)
                  attempts -= 1
                  continue
          for i in range(4):
                  if player_guess[i] not in colors:
                          print (&quot;\nLook up what colors you can use in this game.&quot;)
                          attempts -= 1
                          break
          # comparison between player's input and secret code and player_guess[i] in color_code
          if correct_color != 4:
                  for i in range(4):
                          if player_guess[i] == color_code[i]:
                                  correct_color += 1
                          elif player_guess[i] != color_code[i] and player_guess[i] in color_code and correct_color &gt; prev_curt_color:
                                  guessed_color += 1
                          prev_curt_color = correct_color
                  print(&quot;Correct colour and correct place: &quot;, correct_color)
                  print(&quot;Correct colour and wrong place: &quot;, guessed_color)
  
          if correct_color == 4:
                  if attempts == 1:
                          print (&quot;Wow! You guessed at the first attempt!&quot;)
                  else:
                          print (&quot;Well done... You needed &quot; + str(attempts) + &quot; attempts to guess.&quot;)
                  game = False
  
          if attempts &gt;= 1 and attempts &lt;10 and correct_color != 4:
                  print(&quot;The attempt time &quot; + str(attempts))
                  print(&quot;Next attempt: &quot;)
          elif attempts &gt;= 10:
                  print (&quot;You didn't guess! The secret color code was: &quot; + str(color_code))
                  game = False
  
          # play or not to play
          while game == False:
                  finish_game = input(&quot;\nDo you want to play again (Y/N)?&quot;).upper()
                  attempts = 0
                  if finish_game ==&quot;N&quot;:
                          print (&quot;Thanks for the game! Bye, bye!&quot;)
                          break
                  elif finish_game == &quot;Y&quot;:
                          game = True
                          print (&quot;So, let's play again... Guess the secret code: &quot;)
  </code></pre>