小编Ahs*_*tar的帖子

While True 和条件语句

我试图得到答案m = [0, 2, 0, 4, 0]

m = []
while True:
    for x in range(1, 6):
        if x == 2:
            m.append(x)
            continue
        else:
            m.append(0)
            continue
        if x == 4:
            m.append(x)
            continue
        else:
            m.append(0)
            continue
    break

print(m)
Run Code Online (Sandbox Code Playgroud)

答案来了m = [0, 2, 0, 0, 0]

python loops list

2
推荐指数
1
解决办法
76
查看次数

标签 统计

list ×1

loops ×1

python ×1