Skip to content

Instantly share code, notes, and snippets.

@nodomw
Last active November 11, 2021 16:40
Show Gist options
  • Save nodomw/cd1af0035f40f4a8415f5b5312fb4436 to your computer and use it in GitHub Desktop.
Save nodomw/cd1af0035f40f4a8415f5b5312fb4436 to your computer and use it in GitHub Desktop.
Beugró feladatat Halácsy Péter programjához
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))
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