Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use python to code : For this assignment you will create a version of the popular game mastermind! You can play an online version of

use python to code :image text in transcribedimage text in transcribed

For this assignment you will create a version of the popular game mastermind! You can play an online version of the game here: Mastermind online (Note, your game will look and behave a bit differently) The rules for your game are as follows The computer generates a random password according to the following rules o The password is 5 integers long o The password will consist of integers in the range [1,9] o The password should not have any duplicate values o An example password would be: [9,1,7,4,2] o Every run of the game should generate a different password o The random.sample0 and random.shuffle0 functions can solve this problem trivially, and so their use will result in a mark of 0 for this portion of the assignment. The user then has 10 turns to guess the password. Each turn, the user should be notified of how many turns remain. Each turn the user makes one guess, by entering 5 digits (at a single prompt) Next, the computer reports the the user's result as follows o The number of digits in the user's guess that appear (anywhere) in the password o The number of digits in the user's guess that exactly match the digit in the password (same digit, same position) If the user guesses all five digits correctly (correct digits and correct positions), the game ends with a win message If the user runs out of turns, the game ends with a lose message. This should include a 'cleanly' formatted display of the correct password (e.g 1 2 3 4 5, not [1,2,3,4,5]) When the game ends, your program should ask the user if they would like to play again. This should be a yes or no question, and any invalid input should cause the question to be repeated You may assume that the user correctly enters 5 numbers each turn, however you must allow them to enter all 5 into a single prompt (separated by spaces as in the examples below). (Tip: the string. split0 method might be useful here.) Your code must be structured in a procedural manner. That is, your code should have a main0 method that orchestrates the main logic of your game, and it should have (at minimum) functions to perform the following operations. Please note, your implementation must use the names given here . generatePassword0 This function should generate a random password according to the rules above, and return it as a list. * getUserGuess0 This function should prompt the user for their guess and return a list of the integers that they enterec . reportResult(password,guess) This function should compare the user's guess to the secret password and determine the results according to the rules above. It should display to the user their results (see examples below), and it should return a boolean value: True if the user guessed all 5 digits correctly (i.e., the win condition), and False otherwise

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions