how to add random numbers in python code example
Example 1: python make a random number
# generate random integer values
from random import seed
from random import randint
# seed random number generator
seed(1)
# generate some integers
for _ in range(10):
value = randint(0, 10)
print(value)
Example 2: how to create a random number between 1 and 10 in python
smallest = 0
largest = 100
random_number = random.randint(smallest, largest - 1)
Example 3: python generate list of random numbers
import random
randomlist = []
for i in range(0,5):
n = random.randint(1,30)
randomlist.append(n)
print(randomlist)
Example 4: generate random number python
import random
lower_limit = 0 # Can be anything
upper_limit = 100 # Again, can be anything
# Print it out
print(f"Here is a random number: {random.randint(lower_limit, upper_limit)}
Example 5: random python code
# Here is a literal random python code:
numbers = []
def while_loop(i, x, y):
while i < x:
print(f"At the top i is {i}")
numbers.append(i)
i = i + y
print("Numbers now: ", numbers)
print(f"At the bottom i is {i}")
print("The numbers: ")
for num in numbers:
print(num)
while_loop(0, 6, 1)
# The last number is an incrementor, which specifies how much the variable "i" goes up by.