Oct-14-2018, 04:31 PM
(This post was last modified: Oct-14-2018, 04:32 PM by ichabod801.)
I would put the play loop into it's own function named play or master_mind, and then add an if/name block:
I would also make the multiple print statements a multiline string (with triple quotes), and then print it with one line in the master_mind function.
Avoid looping over indexes. Use enumerate if you need the index as well as the item.
Also, I think this works for white pegs/black pegs, without looping over indexes:
if __name__ == '__main__': master_mind()That way you can import it without the game starting, but running the module itself still plays the game.
return print(feedback)
is redundant. The print function returns None, so that return statement returns None. But functions return None by default, so you don't need the return statement.I would also make the multiple print statements a multiline string (with triple quotes), and then print it with one line in the master_mind function.
Avoid looping over indexes. Use enumerate if you need the index as well as the item.
(code[i])[0]
is the same as code[i][0]
.Also, I think this works for white pegs/black pegs, without looping over indexes:
black_pegs = 0 white_pegs = 0 for color in colours: white_pegs += min(code.count(color), guess.count(color)) for code_peg, guess_peg in zip(code, guess): if code_peg == guess_peg: black_pegs += 1 white_pegs -= black_pegs
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures