0

I'm creating code for the mastermind game and I think that everything should be perfect, but when I try to write the info needed by the first input (in this case, the colors like "R", it doesn't matter what I do that will jump directly to print ("You have to introduce four colours, no more, no less! ")

Can anyone help me please???

Here's the code:

colours=["R", "G", "B", "Y", "W", "R", "P"]
attempts=0
game=True


codemaker=random.sample(colours,4)
print (codemaker)

while game:
    white_points=0
    black_points=0
    guessed_colour=""
    player_guess=input().upper()
    attempts+=1

    if len(player_guess) != len(codemaker):
        print ("You have to introduce four colours, no more, no less! ")
        continue
3
  • 1
    What exactly are you inputing into input? Are you only inputting a single letter? Commented Mar 13, 2019 at 2:03
  • 2
    I could not reproduce the error. I suspect your input is faulty. Commented Mar 13, 2019 at 2:10
  • the result of input is a string. From your code, your input must be a string of 4 letters, e,g, rgby for the len comparison to work Commented Mar 13, 2019 at 2:16

1 Answer 1

1

Do a little lightweight debugging with print and you will see that the code does exactly what you asked it to do: it doesn't print("You have to introduce four colours, no more, no less! ") when the lengths are the same 4:

import random

colours=["R", "G", "B", "Y", "W", "R", "P"]
attempts=0
game=True

codemaker=random.sample(colours,4)
print(len(codemaker), codemaker)

while game:
    white_points=0
    black_points=0
    guessed_colour=""
    player_guess=input().upper()
    attempts+=1
    print(player_guess, len(player_guess))

    if len(player_guess) != len(codemaker):
        print("You have to introduce four colours, no more, no less! ")
        continue

Testing...

4 ['W', 'B', 'R', 'G']
abcde
ABCDE 5
You have to introduce four colours, no more, no less! 
WBRG
WBRG 4
@#$%^U
@#$%^U 6
You have to introduce four colours, no more, no less! 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.