Skip to content

Instantly share code, notes, and snippets.

@harshildarji
Created May 21, 2021 09:28
Show Gist options
  • Save harshildarji/0d506804a9679c89746f9156d5447f1e to your computer and use it in GitHub Desktop.
Save harshildarji/0d506804a9679c89746f9156d5447f1e to your computer and use it in GitHub Desktop.
Color Mastermind Game in Python
def solution(secret, guess):
while secret != guess:
correct_position_guessed = [0] * len(secret)
correct_color_guessed = [color for color in secret if color in guess]
for i in range(len(secret)):
if secret[i] == guess[i]:
correct_position_guessed[i] = 1
print('Correct colors guessed: {}'.format(' '.join(color for color in correct_color_guessed)))
print('Correct positions guessed: {}'.format(correct_position_guessed))
guess = input('> Guess again (separate by space):').split()
print('Finally, your guess is correct!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment