random python between 0 and 1 1

random python between 0 and 1

import random
random.random() # Gives you a number BETWEEN 0 and 1 as a float
round(random.random()) # Gives you a number EITHER 0 and 1 

Here is what the above code is Doing:
1. It’s importing the random module.
2. It’s calling the random function from the random module.
3. It’s calling the round function from the random module.
4. It’s storing the result of the random function in a variable called random_number.
5. It’s storing the result of the round function in a variable called rounded_number.

Similar Posts