Write the game Mastermind using Python. The project is due Try the game out at: http://www.irt.org/games/js/mind/ You'll be creating a command-line version of this game. Here are the rules for Mastermind. 2. The player should enter the full name of each color of a guess, e.g., 'red' or 'blue'. Store the colors in a list. 3. Print out the number of exact and partial matches as the feedback for each guess, e.g., 2 exact, 1 partial. 6. Don't limit the player's guesses-- let them guess forever if they want. 2. Write code to generate the secret code. Use Python's 'random' module. Here's some code to read a single random number between 0 and 5 inclusive: import random # put this at top of file number = random.randint(0,5) You'll need to put the second line within a loop, to get four colors for the secret code, and you'll need to generate a color, e.g., 'red', from each number. Test your code to make sure that it generates a different code each time you run it.
3. Write code that computes the exact matches. This code should compare the colors of a 'guess' list with the colors of a 'secretCode' list
and increment a variable 'exacts' each time there is an exact match. You can test this code separately from (1) and (2)-- just create guess and secret code lists
with fixed values and compare them. 5. Write a loop around parts of the previous code so that the player can repeatedly enter guesses
and received feedback from the system. 6. Add code so that, when the player enters a correct guess (all exact matches), the system prints out a congratulations and tells the user how many guesses were required. Extra CreditAllow the user, when starting a new game, to choose the number of colors, up to ten. You can use a pre-defined set of colors (5 extra points) Allow the user, when starting a new game, to choose the number of slots in a secret code or guess. (5 extra points) Mastermind Grading Format |
