I am currently trying to make a game of mastermind, but with numbers. Here are the specifications.
Program should generate 4 random numbers from 1-9 as the "Secret Code."
User should be prompted for their guess of those four numbers.
After they provide their full guess, the user is told how many are correct.
As long as the user does not get all four correct, they keep getting asked for their guess.
After the user finally gets all four numbers correct, they are congratulated and then told how many tries it took them.
Use at least one list.
Use at least one function with parameters.
Can anyone help me on how to make this?
Should be pretty simple, you should first get what your code is, something like this:
import random numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9'] secret_code = [random.choice(numbers), random.choice(numbers), random.choice(numbers), random.choice(numbers)]
Then, to check how many of the numbers are correct:
def split(word): return [x for x in word] guess = input() guess_list = split(guess) correct = 0 if guess_list == secret_code: correct += 1 #and so on #then print("You got: " + str(correct) + " characters correct!")
You haven't even attempted to make it.
How about this:
You try and make it.
If you run into an error or simply don't know how to do it after at least trying 3 times, then you come to the repl community and ask for help.