Ben k
Ben k

Reputation: 15

Simple python program ran into infinite loop

I am trying to make a simple XOR program. Once I finished checking my syntax, I ran my program and ran into an infinite loop. I can't find my error. Help?

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"))

Upvotes: 1

Views: 80

Answers (2)

herrschmarck
herrschmarck

Reputation: 1

use x += 1 for incrementing x instead of x =+1

Upvotes: 0

ocelot
ocelot

Reputation: 1107

x=+1 should be x += 1, as with your current code, you never increment x, as x =+ 1 is the same thing as x = 1.

You're effectively setting x as 1, never increasing it, and asking the loop to run while x < y, which is infinite.

See here for more information

Upvotes: 2

Related Questions