Finding solution to a crypt equation in python
<p>Consider the equation ABCBA = D * BE * BFFA.The task is to determine where A, B, C, D, E and F which are distinct digits. The equation with numerical values is 91819 = 7 * 13 * 1009, hence the program should print {'A':9, 'B':1, 'C':8 , 'D':7,'E':3, 'F':0}.
Here is the code i did</p>

<pre><code>result=[]
for A in range (10):
    for B in range(10):
        for C in range(10):
            for D in range(10):
                for E in range(10):
                   for F in range(10):
                       if int(str(A)+str(B)+str(C)+str(B)+str(A)) == D * int(str(B)+str(E)) * int(str(B)+str(F)+str(F)+str(A)):
                             result.append({'A':A,'B':B,'C':C,'D':D,'E':E,'F':F})
print((result[len(result)-1]))
</code></pre>

<p>Now that it works for the equation in the example.How sholud I modify my code so that it works for any equation,which is to be input by the user?</p>

<p>If you only need your last output and want to discard everything else you can just overwrite the same variable over and over again:</p>

<pre><code>result = {}
for B in range(10):
    for C in range(10):
        for D in range(10):
            for E in range(10):
                for F in range(10):
                    if int(str(A)+str(B)+str(C)+str(B)+str(A)) == D * int(str(B)+str(E)) * int(str(B)+str(F)+str(F)+str(A)):
                        result = {'A':A,'B':B,'C':C,'D':D,'E':E,'F':F}

pprint(result)
</code></pre>

<p>If you want to keep all results but only print the last one use a list:</p>

<pre><code>result = []
for B in range(10):
    for C in range(10):
        for D in range(10):
            for E in range(10):
                for F in range(10):
                    if int(str(A)+str(B)+str(C)+str(B)+str(A)) == D * int(str(B)+str(E)) * int(str(B)+str(F)+str(F)+str(A)):
                        result.append({'A':A,'B':B,'C':C,'D':D,'E':E,'F':F})

pprint(result[-1])
</code></pre>

python python-3.x cryptography combinations