import random
x = int(input('Enter a number for x: ')) --隨機數最小值
y = int(input('Enter a number for y: ')) --隨機數最大值
n = int(input('How many numbers do you want to create? ')) --生成幾個隨機數
for i in range(1, n+1):
z = random.randint(x, y)
print(z)
運行結果:
>>> import random
>>> x = int(input('Enter a number for x: '))
Enter a number for x: 1
>>> y = int(input('Enter a number for y: '))
Enter a number for y: 100
>>> n = int(input('How many numbers do you want to create? '))
How many numbers do you want to create? 7
>>> for i in range(1, n+1):
z = random.randint(x, y)
print(z)
93
82
48
13
14
83
96
>>>
