How can we find the answer to this equation using python?

Hello I’m kinda new to the mathematics side of Python and I was trying out ways to solve an equation which is:

a * (10**(n-1)) + x = y*x

where ‘y’ and ‘n’ are known and we have to find ‘x’ and ‘a’. Now I’ve tried something which returns an equation to me rather than values:

from sympy.solvers import solve
from sympy import symbols, Eq

def remove_first_digit(n, y):
    a, x = symbols("a,x", integer=True)
    equation = Eq((10 ** (n-1)), ((y-1)*x)/a)
    return solve(equation, (x,a))
print(remove_first_digit(2, 7))

I’m expecting values ‘a’ = 3 and ‘x’ = 5. What am I doing wrong here?


The answer is x = 5a/3 or a = 3x/5, any combination of numbers that satisfies this will work, not just 3 and 5, your program works perfectly. You need to do further operations to reduce the possible answers if you want a = 3 and x = 5.