Question: PYTHON QNS. I need help with QN 4 , I've done qns 3 and my answer is shown below, question 4 is linked with qns
PYTHON QNS. I need help with QN 4, I've done qns 3 and my answer is shown below, question 4 is linked with qns 3. Would appreciate if someone can help me solve it, thank you in advance.
*MODIFY QNS 3 CODE TO USE DICTIONARY TYPE*



My Q3 answer:
import random
print ("MASTERMIND")
print ("Guess the color code")
print ("Enter your color code 'red(R), green(G), blue(B), yellow(Y), orange(O) and purple(P)'")
color = ["R", "G", "B", "Y", "O", "P"]
attempt = 0
master_mind= True
#randomly picks 4 color code
c_code = random.sample(color,4)
print (c_code)
#player guesses the color
while master_mind:
c_color="" #correct color
g_color="" # guessed color player color
p_guess=input()
attempt=attempt+1
#checking player color and comparing with secret color
if len(p_guess)!=len(c_code):
print ("The secret code has exactly 4 colors... Try again...")
continue
for i in range(4):
if p_guess[i] not in color:
print(" please check the given colors")
continue
if c_color != "XXXX":
for i in range(4):
if p_guess[i] == c_code[i]:
c_color=c_color+"X"
if p_guess[i] !=c_code[i] and p_guess[i] in c_code:
g_color=g_color+"O"
print(c_color + g_color )
if c_color=="XXXX":
if attempt==1:
print("guessed at 1st attempt")
else:
print("you succeeded in " + str(attempt) + " no of attempts of guess")
master_mind=False
if attempt>=1 and attempt
print("another try")
elif attempt>=6:
print ("You didn't do correct guess... The secret color code is: " + str(c_code))
while master_mind==False:
finish=input("want to play again(Y/N)")
attempt=0
if finish=="N":
print("GOOD BYE...")
break
elif finish=="Y":
master_mind=True
print("play again guess the orrect code")


Question 3 Develop a simple game application without using the data type dictionary. Allovw any number of players to play MasterMind together For the game design and implementation, you must adhere to the following constraints Start the application by asking the user how many players will be playing MasterMind and the names of the players Before each new game commences, the application randomly generates a hidden code To generate the hidden code, the application makes 4 random choices to pick 4 different colors from 6 colors (stored as a string "RGBYOP" The letters represent the 6 distinct colors: Red, Green, Blue, Yellow, Orange and Purple. The random choices are stored as a single string e.g. "YBRP" Players take turns to make a guess, the order follows the order the names are entered. When it is a player's turn, he guesses the colors and positions of the hidden code. The guess is read as a string and consists of 4 letters e.g., "BORY". The result of his guess is displayed before the next player takes his turn. Show both the before and after score of a player after his guess is checked The next player then takes his turn, each guess is checked and the score updated, until the game ends when the hidden code is broken, that is, a player gets 4 black pins. At the end of each game, print out the details of the players and list the winner(s). The output should be shown on both screen and file The players can repeatedly decide whether to play another game of MasterMind. If the players decide to stop play, print out the players with the most number of games won. The output should be shown on both screen and file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
