Ask coding questions

← Back to all posts
How do you add a program to check white pegs
stubaduble (13)

If you have ever played the classical board game, Mastermind, you will know how it works, guessing a certain combo, black pegs to mark if you got the colour right in the right spot white peg to mark a right colour but in the wrong spot, etc..
does anyone know how to add a white peg checker?

Commentshotnewtop
stubaduble (13)

i am prety sure this does not work..

ash15khng (693)

Basically how I think this could work is just check if every character in the player input is in the answer using the in keyword like this: "a" in "abc".

answer = "RRRR" # pretend this is the answer
player = input("Guess: ") # pretend this is the player input
for letter in player:
    if letter in answer:
        # can be either black or white
        # check for black
    else:
        white_pegs += 1

Hopefully this somewhat helps?

stubaduble (13)

Thanks, that might work for me...
i will have to check it
@ash15khng

stubaduble (13)

This does not work for me..
it said that else does not work..
@ash15khng

ash15khng (693)

@stubaduble I put it 1 indent too high, I will fix it in the original comment.

stubaduble (13)

what do you mean #check for black?
@ash15khng