Currently designing a mastermind game in Python and the requirement is to guess 4 of the colors the system has randomized out of the 6. Is there a way to only choose 4 character strings from the random.shuffle list of 6 characters? When it runs the random right now, it will choose all 6. I have tried the K=4 function but it doesn't work for the random.shuffle function.
import random
def dashes():
print("-----------------------------------------------------------------------")
def mainPage():
print()
print(" M A S T E R M I N D ")
print(" --------------- ")
print()
print("The rules to this Master Mind game is simple. You have to guess the 4 COLORS that I am thinking correctly.")
print()
print(" R U L E S ! ")
print(" ------ ")
print()
print(" 1. YOU only need to guess 4 colors. ")
print()
print(" 2. Please key in the correct keyword for each color. ( Without spaces )")
print(" E.g rbgy ")
print()
print(" 3. List of colors: Red (r), Blue (b), Green (g), Yellow (y), Pink (p), Orange (o) ")
print()
print()
repeat = 'y'
while repeat == 'y' or repeat =='Y':
print()
mainPage()
colorCode = ['r','b','g','y','p','o']
random.shuffle(colorCode)
print(colorCode)
print()
print()
playerGuess = str(input("Guess the color: "))
playerGuess = playerGuess.lower()
print ()
if list(playerGuess) == colorCode:
print("You truly are a M A S T E R M I N D ! ")
print()
repeat = input("Do you DARE to challenge the Master Mind again? You won't be so lucky the second time(Y/N): ")
dashes()
else:
counter = 0
while (playerGuess !=''.join(colorCode)):
counter += 1
count = 0
correct = ['X']*4
for p in range(0,4):
if(playerGuess[p] == colorCode[p]):
count += 1
correct[p] = playerGuess[p]
else:
continue
if (count < 4) and (count != 0):
print("Close! But you did get", count, "correct!")
print("These are the correct guesses. Keep going!")
print()
for k in correct:
print(k, end='')
print()
print()
playerGuess = input("Guess the color: ")
playerGuess = playerGuess.lower()
elif (count == 0):
print("None of your guess are close!")
playerGuess = input("Guess the color: ")
playerGuess = playerGuess.lower()
if playerGuess ==''.join(colorCode):
print()
print("You win!")
print("It took you", counter, "tries")
print()
repeat = input("Do you DARE to challenge the Master Mind again? (Y/N) : ")
dashes()
print()
print()
print(" - P R O G R A M E N D E D - ")