operand one traceback (most recent call last)file "add_input py"line in eval(input('operand ')file ""line in nameerrorname 'oneis not defined in the first of these exampleswe try to add tuple and listwhich one could easily imagine would workbut python does not allow this and therefore the program breaks in the second examplewe try to make the program add two stringswhich usually works finefor instance "one+"onebecomes the string "oneonehoweverthe eval function breaks when we try to input the first string to understand whywe need to think about what the corresponding line really means we try to make the assignment eval('one')which is equivalent to writing onebut this line does not work unless we have already defined variable named one remedy to this problem is to input the strings with quotation marksas in the following example terminal terminalpython add_input py operand "oneoperand "twobecomes with value onetwo these examples illustrate the benefits of the eval functionand also how it easily breaks programs and is generally not recommended for "real programsit is useful for quick prototypesbut should usually be avoided in programs that we expect others to use or that we expect to use ourselves over longer time frame the other "magictext handling function is named execand it is fairly similar to eval howeverwhereas eval evaluates an expressionexec executes string argument as one or more complete statements for instanceif we define string " + "eval(sis illegalsince the value of (" + "is statement (an assignment)and not python expression howeverexec(swill work fine and is the same as including the line + directly in the code the following code illustrates the differenceexpression ' + statement ' + eval(expressionexec(statementprint( , #store expression in string store statement in string results are the same