Ask Question
15 January, 16:39

2.5 Code Practice

Copy and paste the following code into the sandbox window. Modify the code so that the user is asked to multiply two random numbers from 1 to 10

inclusive.

+3
Answers (2)
  1. 15 January, 17:14
    0
    The code solution is written in Python.

    import random num1 = random. randint (1,10) num2 = random. randint (1,10) print (num1 * num2)

    Explanation:

    Firstly, we need two random integers from 1 to 10.

    To generate the two random numbers from 1 to 10 we can use Python randint () method. We can import the random module (Line 1).

    Next, we use dot notation to call the randint () method and pass two values, 1 and 10, as input arguments (Line 2-3). The two input arguments will ensure the randint () will only generate integer between 1 to 10 inclusive. The two random generated integers are stored in variable num1 and num2, respectively

    At last, we multiply num1 and num2 and print the result to terminal (Line 5).
  2. 15 January, 18:56
    0
    import random

    random. seed (1,10)

    a = random. randint (1,10)

    b = random. randint (1,10)

    print ("What is: " + str (a) + " X " + str (b) + "?")

    ans = int (input ("Your answer: "))

    if (a * b = = ans):

    print ("Correct!")

    else:

    print ("Incorrect!")
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “2.5 Code Practice Copy and paste the following code into the sandbox window. Modify the code so that the user is asked to multiply two ...” 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