转自:http://zhidao.baidu.com/link?url=DCRUPZtmAyLDHno812YTk42-ahhFyrejkR98UIJzpPq3zYGoGJc6gNPxtq2SnWJPcHcW5Eatg4is9n2ol3DG5I9lueWMx1S_tMtlaeFF7G3
def solve(eq,var='x'): eq1 = eq.replace("=","-(")+")" c = eval(eq1,{var:1j}) return -c.real/c.imag >>> solve('2*x=5', 'x') 2.5
equation = raw_input('enter equatino:') try: n1, n2 = equation.split('X=') except ValueError: n1, n2 = equation.split('x=') print 'answer is x=%.2f' % (float(n1)/float(n2))