【问题标题】:Simple python program ran into infinite loop简单的python程序陷入无限循环
【发布时间】:2017-03-19 18:31:54
【问题描述】:

我正在尝试制作一个简单的 XOR 程序。完成语法检查后,我运行程序并陷入无限循环。我找不到我的错误。帮忙?

def disencode(n):
    seconde = raw_input("Input_Second_String")
    y = len(n)
    x = 0
    while x < y:
        if n[x] == seconde[x]:
            print 0
        else:
            print 1
        x =+1
disencode(raw_input("Input_First_String"))

【问题讨论】:

    标签: python infinite-loop


    【解决方案1】:

    x=+1 应该是x += 1,与您当前的代码一样,您永远不会增加 x, 因为 x =+ 1 与 x = 1 是一样的。

    您实际上将 x 设置为 1,从不增加它,并要求循环在 x

    See here for more information

    【讨论】:

      【解决方案2】:

      使用x += 1 递增x 而不是x =+1

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-07-29
        • 2021-12-31
        • 1970-01-01
        • 1970-01-01
        • 2015-11-20
        • 2020-05-13
        相关资源
        最近更新 更多