使用python中的while循环更新位列表

我有一点清单。问题是我需要根据我拥有的新位来更新该位的值。这是我的代码示例:


count=1

cycle=3

bit_list = ['1','0','1','0']

new_bit=['1','0','1']

no=''.join(bit_list)

bit=''.join(new_bit)


while (count<=cycle):

    for b in no:

        print (b)

    print ("end of cycle", count)

    def bin_add(*args): return bin(sum(int(x, 2) for x in args))[2:]

    update=bin_add(no,bit)

    count=count+1

print ("updated list",update)

我需要以下输出:


1

0

1

0

updated list 1011  #1010 + 1

end of cycle 1

1

0

1

1

updated list 1011  #1011 + 0

end of cycle 2

1

0

1

1

updated list 1100   #1011 + 1

end of cycle 3

请帮我解决这个问题。谢谢你。


12345678_0001
浏览 155回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python