0

I have a while loop which calls the function mainrt() on each iteration.

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

And the mainrt()

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

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

INPUT
3
5

OUTPUT SHOLD BE
30
90

But instead I get
30
5

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

1 Answer 1

1

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

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

for n in inpList:

    diMon = []
    i = 0
    p = 0
    n  = int (n)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.