Created
May 21, 2021 09:28
-
-
Save harshildarji/0d506804a9679c89746f9156d5447f1e to your computer and use it in GitHub Desktop.
Color Mastermind Game in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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