Computer Science
Out of random() and randint(), which function should we use to generate random numbers between 1 and 5. Justify.
Python Modules
1 Like
Answer
To generate random numbers between 1 and 5, we should use the randint()
function from the random
module. The randint(a, b)
function accepts two parameters, a and b, as the lowest and highest number, returns a number N in the inclusive range [a, b], which signifies a <= N <= b. This function generates a random integer number between two given numbers. In contrast, the random()
function generates a random floating point number from 0 to 1.
Answered By
3 Likes
Related Questions
Rewrite the following Python code after removing all syntax error(s). Underline the corrections done.
def main(): r = input('enter any radius:') a = pi * maths.pow(r, 2) Print("Area = "+a) Main()
How is math.ceil(89.7) different from math.floor(89.7)?
What is the difference between import statement and from import statement?
Why is from import* statement not recommended for importing Python modules in an external program?