हिंदी

Out of random() and randint(), which function should we use to generate random numbers between 1 and 5? Justify. - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Out of random() and randint(), which function should we use to generate random numbers between 1 and 5? Justify.

टिप्पणी लिखिए

उत्तर

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
Types of Module - Built-in Modules
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 7: Functions - Exercise [पृष्ठ १७०]

APPEARS IN

एनसीईआरटी Computer Science [English] Class 11
अध्याय 7 Functions
Exercise | Q 3. | पृष्ठ १७०
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×