Ask Question
29 May, 12:46

Define a function called guessNumber that implements the following game, in which the computer will: • Think of a random number in the range 0-50. (Hint: use the random module.) • Repeatedly prompt the user to guess the mystery number. • If the guess is correct, congratulate the user for winning. If the guess is incorrect, let the user know if the guess is too high or too low. • After 5 incorrect guesses, tell the user the right answer.

The following is an example of correct input and output.

I'm thinking of a number in the range 0-50. You have five tries to guess it.

Guess 1? 32

32 is too high

Guess 2? 18

18 is too low

Guess 3? 24

+1
Answers (1)
  1. 29 May, 15:15
    0
    import random

    arr=[]

    for i in range (50):

    arr. append (i)

    for j in range (5):

    answer=random. choice (arr)

    guess=int (input ("enter your guess number between 0-50: "))

    if answer is guess:

    print ("right guess/ncongratulations ... ")

    print ("the answer was: "+str (answer))

    break

    elif guess < answer-10:

    print ("you guessed too low ... / ntry again")

    print ("the answer was: "+str (answer))

    elif guess > answer+10:

    print ("you guessed too high ... / ntry again")

    print ("the answer was: "+str (answer))

    else:

    print ("incorrect guess/ntry again")

    print ("the answer was: "+str (answer))

    Explanation:

    the code is in Python programming language.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Define a function called guessNumber that implements the following game, in which the computer will: • Think of a random number in the ...” 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