मराठी

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.

टीपा लिहा
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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 7: Functions - Exercise [पृष्ठ १७०]

APPEARS IN

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

Englishहिंदीमराठी


      Forgot password?
Use app×