Ask Question
2 June, 20:00

Write a Raptor program that will generate a random number between 1 and 100; do not display the randomly generated number. Let the user guess within 3 tries what the random number is. Display appropriate messages based on each try, for example, "1 remaining try" or "You guessed correctly!"

+2
Answers (2)
  1. 2 June, 23:25
    0
    The answer to this question can be given as:

    Program:

    #include / /include header file.

    #include / /include header file.

    int main () / /main method.

    {

    int number, choice; / /define variable.

    number = rand () % 10 + 1; / /use random function and take value in number variable

    for (int i=1; i<=3; i++) / /loop for 3 time input.

    {

    printf ("/n Enter the Guess number between 1 to 10 : /n"); / /message

    scanf ("%d",&choice); / /input a number

    if (number
    {

    printf ("Number is to lower/n try = %d", i); / /message

    }

    else if (number>choice) / /check number

    {

    printf ("Number is to higher/n try = %d", i); / /message

    }

    else if (number==choice ||number!=choice) / /check number

    {

    printf ("Congratulations ... ! / n You guessed correctly!/n"); / /message

    break;

    }

    }

    printf ("/n Number is : %d/n", number); / /value

    return 0;

    }

    Output:

    Enter the Guess number between 1 to 10:

    5

    Number is to lower

    try = 1

    Enter the Guess number between 1 to 10:

    8

    Number is to lower

    try = 2

    Enter the Guess number between 1 to 10:

    6

    Number is to lower

    try = 3

    Number is: 4

    Explanation:

    The above C language program can be described as:

    In this program firstly we include header files. Then we define the main function in this function we define a variable that is number and choice. The number variable holds the value of the random number that is taken by the rand function. Then we define the loop. This loop is used to provide input validation. This means the user input number only three times. In this loop, we take input by the user in the choice variable. Then we use the conditional statement. In this statement, we check the numbers. If the value match in 3 inputs so, it will print the message "Congratulations ... ! You guessed correctly!". Otherwise, we will print the random function value.
  2. 2 June, 23:32
    0
    Let's do this in Python, we can first generate the random number from 1 to 100. Then compare that with the input number from the guesser.

    from random import random

    random_0_1 = random ()

    random_1_100 = 1 if round (100*random_0_1) < 1 else round (100*random_0_1)

    for trial in range (3):

    guess = input ('Guess the number: ')

    if guess = = random_1_11:

    print ('You guessed correctly!')

    break

    else:

    print (2 - trial + " remaining try")
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a Raptor program that will generate a random number between 1 and 100; do not display the randomly generated number. Let the user ...” 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