Python Forum
Mastermind/Guess the Code Game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mastermind/Guess the Code Game
#2
I would put the play loop into it's own function named play or master_mind, and then add an if/name block:

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
Reply


Messages In This Thread
Mastermind/Guess the Code Game - by JoeLamond - Oct-14-2018, 01:29 PM
RE: Mastermind/Guess the Code Game - by ichabod801 - Oct-14-2018, 04:31 PM
RE: Mastermind/Guess the Code Game - by JoeLamond - Oct-16-2018, 02:55 PM
RE: Mastermind/Guess the Code Game - by ichabod801 - Oct-16-2018, 07:18 PM
RE: Mastermind/Guess the Code Game - by ichabod801 - Oct-16-2018, 07:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Guess your number joe_momma 0 2,475 Oct-23-2020, 02:53 AM
Last Post: joe_momma
  Guess my number foksikrasa 0 2,421 May-28-2020, 04:12 PM
Last Post: foksikrasa
  guess my number GAME ronblue77 2 2,807 Nov-24-2019, 04:23 PM
Last Post: CodingStranger
  Guess the dice roll mini-game tawnnx 6 7,419 May-22-2018, 02:12 PM
Last Post: malonn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020