尝试:
from random import randint
print(randint(0, 9))
更多信息: https : //docs.python.org/3/library/random.html#random.randint
import random
print(random.randint(0,9))
random.randint(a, b)
返回一个随机整数 N,使得 a <= N <= b。
文档: https : //docs.python.org/3.1/library/random.html#random.randint
试试这个:
from random import randrange, uniform
# randrange gives you an integral value
irand = randrange(0, 10)
# uniform gives you a floating-point value
frand = uniform(0, 10)