Hard
Expression Tree
Write
class Node with methods value() and __str__ that subclasses override: Num(n), Add(left, right) and Mul(left, right). Read an expression in prefix form with spaces, like + 2 * 3 4, build the tree recursively, and print it fully bracketed ((2 + (3 * 4))) and its value.Input
One line.
Output
Two lines.
Sample 1
Input
+ 2 * 3 4
Output
(2 + (3 * 4)) 14
Sample 2
Input
7
Output
7 7
Output appears here