Ask Question
15 February, 07:43

Write a program that plays a reverse guessing game with the user. The user thinks of a number between 1 and 10, and the computer repeatedly tries to guess it by guessing random numbers. It's fine for the computer to guess the same random number more than once. At the end of the game, the program reports how many guesses it made.

+4
Answers (1)
  1. 15 February, 08:39
    0
    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))

    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).
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that plays a reverse guessing game with the user. The user thinks of a number between 1 and 10, and the computer repeatedly ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers