Last active
November 11, 2021 16:40
-
-
Save nodomw/cd1af0035f40f4a8415f5b5312fb4436 to your computer and use it in GitHub Desktop.
Beugró feladatat Halácsy Péter programjához
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
import random | |
colors = ["red", "green", "blue", "purple", "yellow", "orange", "black", "white", "brown"] | |
code = random.sample(colors, 4) | |
guess = [] | |
print("enter colors (4 max, press enter after an entry)") | |
print(code) | |
for i in range(0, 4): | |
i = str(input("> ")) | |
guess.append(i) | |
print(set(code).intersection(guess)) |
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
colors = ["red","green","blue","white"] | |
guessed = [] #"red","yellow","white","black" | |
result = [] | |
def startGame(): | |
for i in range(0, 4): | |
colorString = input() | |
guessed.append(colorString) | |
resultList = compare(colors, guessed) | |
print(resultList) | |
def compare(colors, guessed): | |
result = [] | |
for index in range(0, 4): | |
if isMatch(guessed[index], colors): | |
if isGoodPlace(colors[index], guessed[index]): | |
result.append("black") | |
else: | |
result.append("white") | |
return result | |
def isMatch(color, colorList): | |
return color in colorList | |
def isGoodPlace(color,guess): | |
return color == guess | |
startGame() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment