python中的随机数

0 python

我想使用 python 打印随机数。如果我使用 random.randint(1, 10) 它会给我 1-10 的随机数。如果我想打印 1-10 之间的随机数但不包括数字 2 怎么办?谢谢你

Jam*_*mes 5

您可以使用random.choice

print(random.choice([1, 3, 4, 5, 6, 7, 8, 9, 10]))
Run Code Online (Sandbox Code Playgroud)