问题遇到的现象
[6, 5, 8, 6, 2, 5, 0, 2, 7, 3]
运算后的: [6, 5, 8, 6, 2, 5, 0, 2, 7, 3] -bug 这个3 没有执行 + 2
[4, 2, 5, 6, 6, 0, 5, 6, 5, 4]
[5, 1, 0, 3, 4, 9, 0, 4, 9, 5]
运算后的: [5, 1, 0, 5, 4, 9, 0, 4, 9, 5]
[6, 9, 1, 6, 6, 5, 9, 1, 5, 9]
[5, 0, 3, 3, 9, 3, 0, 5, 1, 9]
运算后的: [5, 0, 3, 5, 9, 5, 0, 5, 1, 9]
[1, 3, 2, 0, 0, 7, 0, 4, 0, 1]
运算后的: [1, 5, 2, 0, 0, 7, 0, 4, 0, 1]
[3, 2, 6, 4, 6, 8, 7, 3, 4, 9]
运算后的: [3, 2, 6, 4, 6, 8, 7, 5, 4, 9]
[8, 6, 4, 8, 0, 7, 4, 4, 7, 7]
问题相关代码
import random
# while True:
for i in range(0, 10):
xs = []
for i in range(0, 10):
x = random.randint(0, 9)
xs.append(x)
print(xs)
if 3 in xs:
for i in xs:
if xs[i] == 3:
xs[i] += 2
print('运算后的:', xs)
运行结果
[6, 5, 8, 6, 2, 5, 0, 2, 7, 3]
运算后的: [6, 5, 8, 6, 2, 5, 0, 2, 7, 3] bug在这里 有个 3 没有执行 + 2
[4, 2, 5, 6, 6, 0, 5, 6, 5, 4]
[5, 1, 0, 3, 4, 9, 0, 4, 9, 5]
运算后的: [5, 1, 0, 5, 4, 9, 0, 4, 9, 5]
[6, 9, 1, 6, 6, 5, 9, 1, 5, 9]
[5, 0, 3, 3, 9, 3, 0, 5, 1, 9]
运算后的: [5, 0, 3, 5, 9, 5, 0, 5, 1, 9]
[1, 3, 2, 0, 0, 7, 0, 4, 0, 1]
运算后的: [1, 5, 2, 0, 0, 7, 0, 4, 0, 1]
[3, 2, 6, 4, 6, 8, 7, 3, 4, 9]
运算后的: [3, 2, 6, 4, 6, 8, 7, 5, 4, 9]
[8, 6, 4, 8, 0, 7, 4, 4, 7, 7]
这是哪里写出了bug么?