Python does not start for loop
<pre><code>old = [[0 for x in range(3)] for y in range(10)]
count =0
# check if the number has non-repeating digits
def different(number):
    digit_list = [0] * 4
    i = 0
    while i:
        digit_list[i] = number%10
        number /= 10
        i += 1

    for x in range(0,3):
        for y in range(x+1,3):
            if digit_list[x] == digit_list[y]:
                return False
    return True
# save the tried numbers, plus and minus values
# for prediction of the next number
def save(number,plus,minus):
    global count
    old[count][0] = number
    old[count][1] = plus
    old[count][2] = minus
    count += 1
    return
# compare for plus values
def get_plus(number1,number2):
    ret_value = 0
    for x in range(0, 3):
        if number1 % 10 == number2 % 10:
            ret_value += 1
        number1 /= 10
        number2 /= 10
    return ret_value
# compare for minus values
def get_minus(number1,number2):
    temp = [[0]*4 for i in range(2)]
    ret_value = 0
    for x in range(0,3):
        temp[0][x] = number1 % 10
        temp[0][x] = number2 % 10
        number1 /= 10
        number2 /= 10
    for x in range(0,3):
        for y in range(0,3):
            if x != y:
                if temp[0][x] == temp[1][y]:
                    ret_value += 1
    return ret_value
# compare the number to be asked with the numbers in the array
def control(number):
    for x in range(0,count-1):
        if get_plus(old[x][0],number) != old[x][1]:
            return False
        if get_minus(old[x][0],number) != old[x][2]:
            return False
    return True

def main():
    flag = False
    print('1023 ??')
    plus = input('plus ?')
    minus = input('minus ?')
    save(1023, plus, minus)
    print('4567 ??')
    plus = input('plus ?')
    minus = input('minus ?')
    save(4567, plus, minus)

    for i in range(1024, 9876):
        if different(i):
            if control(i):
                print(i + ' ??')
                plus = input('plus ?')
                minus = input('minus ?')
                save(i, plus, minus)
                if plus == 4 and minus == 0:
                    print('I WON !!!')
                    flag = True
                    break
    if not flag:
        print('False')
    return
main()
</code></pre>

<p>I am trying to make an AI for mindgame in python. But in this function it doesn't even start the for loop. Can anyone know why ? </p>

<p>The while loop in your different() function does nothing as while(0) will prevent the loop from running. Even if that would run, your different() function will always return false. At least in the last loop it will compare digit_list[3] == digit_list[3] as both loop range until 3. This is always true and the function will return false. Thus the code within your main loop will never be entered.</p>

<pre><code>def different(number):
    digit_list = [0] * 4
    i = 0
    while i:
        digit_list[i] = number%10
        number /= 10
        i += 1

    for x in range(0,3):
        for y in range(x+1,3):
            if digit_list[x] == digit_list[y]:
                return False
    return True
</code></pre>

<p>Try this one:</p>

<pre><code>import random

def different(num):
    digits = []
    while num &gt;= 1:
        cur = num%10
        if cur in digits:
            return False
        digits.append(cur)
        num = (num - cur) / 10
    return True

for i in range(0, 10000):
    rand = random.randrange(1000, 10000)

    if not different(rand):
        print(rand)
</code></pre>

python python-3.x for-loop