Tag: number
python random number between 1 and 100
Using the random module, we can generate pseudo-random numbers. The function random() generates a random number between zero and one [0, 0.1 .. 1]. Numbers generated with this module are not truly random but they are enough random for most purposes.
Related Course:
Python Programming Bootcamp: Go from zero to hero
Random number between 0 and 1.
We can generate a (pseudo) random floating point number with this small code:
from random import * |
Generate a random number between 1 and 100
To generate a whole number (integer) between one and one hundred use:
from random import * |
This will printa random integer. If you want to store it in a variable you can use:
from random import * |
Random number between 1 and 10
To generate a random floating point number between 1 and 10 you can use the uniform() function
from random import * |
Picking a random item from a list
Fun with lists
We can shuffle a list with this code:
from random import * |
To pick a random number from a list:
from random import * |
We can do the same thing with a list of strings:
from random import * |
If you are new to Python programming, I highly recommend this book.