# L-31 MCS 260 Wed 7 Nov 2007 : dyneval.py # # Thanks to Python's dynamic typing, # expressions may be evaluated dynamically # as well, via the "eval" command. # Any valid Python expression the user # enters will be evaluated at the given x. from math import * e = raw_input('f(x) = ') x = input('x = ') y = eval(e) print e + ' at x = ' + str(x) print 'equals ' + str(y)