Python: Problems in calling the function from the while loop
<p>I have a while loop which calls the function mainrt() on each iteration.</p>

<pre><code>if __name__ == "__main__":
    inp = sys.stdin.read()
    inpList = inp.split('\n')
    inpList.pop()
    for n in inpList:

        i = 0
        p = 0
        n  = int (n)
        while True:
            i += 1
            p = n*i
            if n == 0:
                print "INSOMNIA"
                break
            else:
                res = True
                res = mainrt(p)
                if res == False:
                    print p
                    break
</code></pre>

<p>And the mainrt()</p>

<pre><code>def mainrt(n):
    #print n

    while True:
        rem = n % 10
        if rem in diMon:
            pass
        else:
            diMon.insert(rem,rem)

        if len(diMon) == 10:

            return False
            break

        n = n/10
        if n == 0:
            return True
            break
        else:
            continue
</code></pre>

<p>The problem is as i take input from stdin.read() the first line of the input processed properly by the function, but the second line of the input get printed as it is. It is not being processed by the function
example</p>

<pre><code>INPUT
3
5

OUTPUT SHOLD BE
30
90

But instead I get
30
5
</code></pre>

<p>Why the function not processing the input the second time???
There is no run time error so far.</p>

<p>In your <code>mainrt</code> function I do not see that you declare <code>diMon</code> list, so it looks like it is a global variable and you do not clean that list. That mean your <code>mainrt</code> return <code>False</code> at the first check of <code>if len(diMon) == 10:</code> for the second input. You should declare <code>diMon</code> at the beginning od <code>mainrt</code> function or clear it at the end of while loop body.</p>

<p><strong>EDIT:</strong>
Now I checked your code one more time and I suggest you to declare diMon at the beginning of <code>for</code> loop</p>

<pre><code>for n in inpList:

    diMon = []
    i = 0
    p = 0
    n  = int (n)
</code></pre>

python python-2.7