So I am trying to add a graphical element to my game. And it draws a circle for white or black pegs. However, the list that contains "Black" and "White" isn't acting quite like I want.
The list prints like this:
But I want it to print like:
so I can do this:
print len(self.hints) for i in range(len(self.hints)): print self.hints[i] if self.hints[i] == "Black": blackPeg = Circle(Point(50 + i*30, 250), 12) blackPeg.setFill("black") blackPeg.setOutline("black") blackPeg.draw(win) elif self.hints[i] == "White": whitePeg = Circle(Point(200 + i*30, 250), 12) whitePeg.setFill("white") whitePeg.setOutline("white") whitePeg.draw(win)
This generates the Black and White list:
class Hints: def __init__(self, guess, secretCode): self.guess = guess self.secretCode = secretCode def hints(self): #Creates a list for the hints hint =  guessCopy = list(self.guess) secretCodeCopy = list(self.secretCode) for i in range(len(guessCopy)): if guessCopy[i] == secretCodeCopy[i]: hint.append("Black") secretCodeCopy[i] = "X" guessCopy[i] = "Y" for i in range(len(guessCopy)): for j in range(len(secretCodeCopy)): if guessCopy[i] == secretCodeCopy[j]: hint.append("White") secretCodeCopy[j] = "Z" break #If no numbers in the guess are correct, there are no hints given if len(hint) == 0: return "" hint.sort() return " ".join(hint)
Thanks for the help.