I'm trying to create a python program for solving equations:
from sympy import symbols, Eq, solve
list1 = ['x', 'y'] #<--- Letters of the user input
list1[0] = symbols(list1[0]) #<--- Assignment of the unknown x
list1[1] = symbols(list1[1]) #<--- Assignment of the unknown y
eq1 = Eq(x*2 - 5*x + 6 + y, 0) #<--- Equation
res = solve(eq1, dict=True) #<--- Solving
print(res)
I want assign a value to the first and the second object of the 'list1', in this case 'x = symbols('x')' and 'y = symbols('y')'. So I tried replacing the 'x' with list1[0] and the 'y' with list1[1] because it can be any letter based on user input. But the script still saying 'x is not defined' at the sixth line. So, is there a way to assign a value to an item of an array?
See Question&Answers more detail:os