1.

How can you generate random numbers?

Answer»

Python PROVIDES a module called random using which we can generate random numbers.

  • We have to import a random module and call the random() method as shown below:
    • The random() method generates float values LYING between 0 and 1 randomly.
import random print(random.random())
  • To generate CUSTOMISED random numbers between SPECIFIED ranges, we can use the randrange() method
    Syntax: randrange(beginning, END, step)
    For example:
import randomprint(random.randrange(5,100,2))


Discussion

No Comment Found