Answer:
- import random
-
- target = 7
- count = 0
- for i in range(100):
- guess = random.randint(1,10)
-
- if(guess == target):
- count += 1
-
- print("Total of correct guess: " + str(count))
Step-by-step explanation:
The solution is written in Python 3.
Firstly, import the random module since we are going to simulate the random guess by computer. Next, we presume user set a target number 7 (Line 3). Create a counter variable to track the number of correct guess (Line 4).
Presume the computer will attempt one hundred times of guessing and we use randint to repeatedly generate a random integer between 1 - 10 as guess number (Line 6). If the guess number is equal to the target, increment count by one (Line 8-9).
Display the total number of right guess to terminal (Line 11).