Question: Here's my code: import random class Secret_Number: def __init__(self): while(True): num =random.randint(102,987) number=num list=[] guess=0 while(number>0): list.append(number%10) number = number//10 for item in list: count=list.count(item)

![=random.randint(102,987) number=num list=[] guess=0 while(number>0): list.append(number%10) number = number//10 for item in](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f0098bcf897_11566f0098b60ade.jpg)
Here's my code:
import random class Secret_Number: def __init__(self): while(True): num =random.randint(102,987) number=num list=[] guess=0 while(number>0): list.append(number%10) number = number//10 for item in list: count=list.count(item) if(count>=2): guess=1 break if guess==1: continue else: break self.number=str(num)
def get(self): return self.number
def getClues(self,guess): clue="" i=0 for digit in guess: if digit in self.number and digit == self.number: clue +="CORRECT" elif(digit==self.number[i]): clue+="Ding " elif digit in self.number: clue+="Dong "
i+=1 if(clue==""): return "Wrong" else: return clue
def readNumber(guessAttempt): while(True): print("Enter a three digit number with non-repeating digits") guessNumber=input("Guess attempt {}:".format(guessAttempt)) guess=0 if(len(guessNumber)!=3 or (guessNumber.isdigit())==False) or guessNumber not in guessNumber: continue l=list(guessNumber) for digit in l: count=l.count(digit) if(count>=2): guess=1 break if guess==1: continue else: break return guessNumber
def main(): answer= Secret_Number() answer = answer.get() print (answer) guessAttempt=1 win=False print("I am thinking of three digit number. Try to guess what it is. You have 10 attempts.") print("If you will guess numberne of the digit i will answer WRONG.") print("I will answer DING for every currect digit in the right position.") print("and will answer DONG for every currect digit in the wrong position. ") while True: secretNumber=Secret_Number() while(guessAttempt
if __name__ == '__main__': main()
My problem is with the printing of CORRECT, DING, DONG, WRONG. Even when I input the correct number something else is being printed. Can you please help me fix it the way its instructed in C. ?
Thank you
Lab exercise Week 5 You are asked to program a simple number guessing game. The computer will generated a secret number, with 3 digits that do not repeat, between 102 and 987. The game consists in guessing this 3 digit number in a maximum of 10 attempts Here is an example of execution. I am thinking of a 3 digit number. Try to guess what it is. You have 10 attempts If you guess none of the digits I will answer WRONG I will answer DING for every correct digit in the right position and wiII answer DONG for every correct digit ln the wrong position Enter a three digit number with non-repeating digits Guess attempt 1:123 DING DONG Enter a three digit number with non-repeating digits Guess attempt 2:124 DING Enter a three digit number with non-repeating digits Guess attempt 3:245 WRONG Enter a three digit number with non-repeating digits Guess attempt 4:136 DING DING Enter a three digit number with non-repeating digits Guess attempt 5:137 DING DING Enter a three digit number with non-repeating digits Guess attempt 6:138 DING DING Enter a three digit number with non-repeating digits Guess attempt T:139 You guessed it after 7 attempts. The number is indeed 139 Do you want to play again (Y/N)? c. The method also has the method getClues) which receives a guess as a string with 3 digits and returns the string "CORRECT" if the guess matches the property number, "WRONG" if none of the digits match, or a string with as many "DING" as there are digits that match and in the correct position and as many DONG for digits that match but are not in the correct position. For instance, here are examples of output for different guesses if the secret number is 123: 456 WRONG 729 DING 102 DING DONG 120 DING DING 132 DING DONG DONG 123 CORRECT
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
