Advertisements
Advertisements
प्रश्न
Out of random() and randint(), which function should we use to generate random numbers between 1 and 5? Justify.
टीपा लिहा
Advertisements
उत्तर
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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
