Python 生成随机数

python

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
>>>

 

以上是 Python 生成随机数 的全部内容, 来源链接: utcz.com/z/388034.html

回到顶部