很抱歉无法正确解释。
reel = ["c", "a", "c", "c", "a", "c", "d", "d", "b", "b", "b", "b", "a",
"b"]
outcome = ["A","A",0,0,0,0,0,0,"A","A"]
x = randint(0, len(reel1)-1)
让我们说x = len(reel1)-2。我们希望通过reel [len(reel1)-2],reel [len(reel1)-1],reel [0]等感受“结果”中的所有0。只是x中0的数量会变化,我需要一个通用方法。
答案 0 :(得分:1)
我想我了解您在这里要做什么;
say卷轴= [0,1,2,3,4,5,6,7] 您想要得到结果= [6,7,0,1,2,3,4,5]
这项工作吗?
from random import randint
reel = [0,1,2,3,4,5,6,7]
start = randint(min(reel),max(reel))
outcome = reel[start:]
outcome.extend(reel[:start])
答案 1 :(得分:0)
不确定我是否理解正确,但这可能会有所帮助:
from random import randrange
x = [1,2,3,4,5,6]
start = randrange(len(x)) # 2
o = x[start:] + x[:start] # [3, 4, 5, 6, 1, 2]