设计程序,从[O,100]中随机取一个3的倍数。

设计程序,从[O,100]中随机取一个3的倍数。
import random
for x in range[1,101]:
ifx % 3==0
print(x,end =' ')
print(x)
random.seed()
y=random.sample(1ist(x),1)
print(y)


import random

while True:
    x = random.randint(1, 100)
    if x % 3 == 0:
        print(x)
        break

最大值100除以3取整 得到33
1到33随机
随机的结果乘3
得到3的倍数


import random
l = []
for x in range(1,101):
    if x % 3==0:
        l.append(x)
print(random.choice(l))