user input and error handling we can also use exec to execute multiple statementsfor instance using multi-line stringssomecode ""def ( )term exp(- * )*sin( *xterm *sin( *xreturn term term ""exec(somecodeexecute the string as python code herethe exec line will simply execute the string somecodejust as if we had typed the code directly in our program after the call to exec we have defined the function (tand can call this function in the usual way although this example does not seem very usefulthe flexibility of exec becomes more apparent if we combine it with actual user input for instanceconsider the following codewhich asks the user to type mathematical expression involving and then embeds this expression in python functionformula input('write formula involving 'code ""def ( )return {formula""from math import make sure we have sincoslogetc exec(codeturn string formula into live function #now the function is definedand we can ask the #user for values and evaluate (xx while is not nonex eval(input('give (none to quit)')if is not noney (xprint( ' ({ })={ }'while the program is runningthe user is first asked to type formulawhich becomes function then the user is asked to input values until the answer is noneand the program evaluates the function (xfor each the program works even if the programmer knows nothing about the user' choice of (xwhen the program is writtenwhich demonstrates the flexibility offered by the exec and eval functions to consider another examplesaywe want to create program diff py that evaluates the numerical derivative of mathematical expression (xfor given value of the mathematical expression and the value will be given as command line arguments the program could be used as followsterminal terminalpython diff py 'exp( )*sin( ) numerical derivative-