In the function, reassign computerNumber to a random number between 1 and 3 (use randomInt() )
Question
In the function, reassign computerNumber
to a random number between 1 and 3 (use randomInt()
)
Solution
To reassign computerNumber
to a random number between 1 and 3 using the hypothetical function randomInt()
, follow these steps:
1. Define the Function
Ensure that randomInt()
is defined to generate random integers. The function should take two parameters representing the inclusive range.
2. Reassignment
Reassign computerNumber
using the function to get a random integer within your specified range.
Example Code
# Assuming a randomInt function is defined as follows:
import random
def randomInt(min, max):
return random.randint(min, max)
# Reassign computerNumber
computerNumber = randomInt(1, 3)
Final Answer
The variable computerNumber
will now hold a random integer between 1 and 3, inclusive.
Similar Questions
On Python line 5, use random.randint() to generate a number between 0 and 2, and store the result to a variable named randomNumber.
Which of these method return a pseudorandom number?Optionsrandom()rand()randomNumber()randGenerator()
Which of the following options is the best for generating random integer 0 or 1?
Which of the following is correct to obtain a random integer between 5 and 10 (inclusive)?
Jalen randomly chooses a number from 1 to 10. What is the probability he chooses a number greater than 3?A.B.C.D.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.