Advertisements
Advertisements
Question
Out of random() and randint(), which function should we use to generate random numbers between 1 and 5? Justify.
Short/Brief Note
Advertisements
Solution
The 'randint(a,b)' function will return a random integer within the given range as parameters.
'random()' function generates a random floating-point value in the range (0,1)
Therefore, to generate a random number between 1 and 5 we have to use the randint(1,5) function.
Note: 'randint()' is a part of 'random' module so, before using the same in the program, it has to be imported using the statement ‘from random import randint’.
shaalaa.com
Is there an error in this question or solution?
