Ask Question
17 July, 03:54

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. 17 July, 06:18
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers