I wrote piece of code that takes an equation from the user and evaluate the right hand side and the left hand side separately to check if the equation is balanced. If there is an undefined variable it catches a NameError exception. I want to modify that to check if only on variable is not defined in the dictionary I want the program to solve for that variable and add it to the dictionary. How can I do that? Here is my code
eq=input("Enter an equation")
answer=eq.split("=")
lhs=answer[0]
rhs=answer[1]
try:
rhs_value=eval(rhs,dict)
lhs_value=eval(lhs,dict)
except NameError:
print("Undefiened varaible")
else:
if(rhs_value==lhs_value):
print("Your equation is correct")
else:
print("Your equation is incorrect")
let's say the user enters Vs=(-5*g)+Vs. g is defined in dict but not Vs. I want it to solve for Vs and add it to the dictionary. but if both variables are undefined it would print something like too many variables to solve for