因此,我正在为一次数值垫编写一个脚本,但问题是,我希望这些数值的结果保持在0到10的特定范围内,这样,
2-4=9 [9, 10, 0, 1, 2]
4-9=6 [6, 7, 8, 9, 10, 0, 1, 2, 3, 4]
7+8=4 [7, 8, 9, 10, 0, 1, 2, 3, 4]这是我的剧本
#list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
#sum = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0] 1 = addition, 0 = subtraction
#of = [2, 4, 3, 9, 5, 6, 8, 7, 0, 1,]
length = len(list)
i = 0
while i < length:
x = list[i]
s = sum[i]
y = of[i]
if s == 1:
z = x + y
else:
z = x - y
print(z)
i += 1发布于 2022-03-12 16:12:26
您需要使用模算法
>>> (2-9)%11
4
>>> (4-9)%11
6
>>> (7+8)%11
4https://stackoverflow.com/questions/71451138
复制相似问题