Question: need def simplify(e) so that the assertions can work for it ## Tests for simplify. 2 points. e = ('+', 6, ('-', 7, 2)) assert
need def simplify(e) so that the assertions can work for it


## Tests for simplify. 2 points. e = ('+', 6, ('-', 7, 2)) assert simplify(e) == 11 (D = ('+', 6, ('-', "x", 2)) assert simplify (e) e (D = ('+', "cat", ('-', 7, 2)) assert simplify (e) ('+', "cat", 5) == e = ('*', ('+', 2, 3), ('-', 7, 2)) assert simplify (e) == 25 (D = ('*', ('+', 2, 3), ('-', 7, "monkey")) assert simplify (e) ('*', 5, ('-', 7, 'monkey')) == def simplify_once(e): if isnumber(e) or isvariable(e): # No simplification possible. return e else: op, l, r = e if isnumber(1) and isnumber(r): return calc(op, l, r) else: # We cannot do anything. return e Write a version of simplify that is able to carry on computation on multi-level expressions, including (but not limited to) ('+', 6, ('-', 7, 2)). ## Tests for simplify. 2 points. e = ('+', 6, ('-', 7, 2)) assert simplify(e) == 11 (D = ('+', 6, ('-', "x", 2)) assert simplify (e) e (D = ('+', "cat", ('-', 7, 2)) assert simplify (e) ('+', "cat", 5) == e = ('*', ('+', 2, 3), ('-', 7, 2)) assert simplify (e) == 25 (D = ('*', ('+', 2, 3), ('-', 7, "monkey")) assert simplify (e) ('*', 5, ('-', 7, 'monkey')) == def simplify_once(e): if isnumber(e) or isvariable(e): # No simplification possible. return e else: op, l, r = e if isnumber(1) and isnumber(r): return calc(op, l, r) else: # We cannot do anything. return e Write a version of simplify that is able to carry on computation on multi-level expressions, including (but not limited to) ('+', 6, ('-', 7, 2))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
