diff --git a/README.md b/README.md index 91887c7..66a08ad 100644 --- a/README.md +++ b/README.md @@ -1110,16 +1110,19 @@ def evaluate(expression): return eval_node(root.body) def eval_node(node): - type_ = type(node) - if type_ == Num: + node_type = type(node) + if node_type == Num: return node.n - if type_ not in [BinOp, UnaryOp]: + if node_type not in [BinOp, UnaryOp]: raise TypeError(node) - operator = legal_operators[type(node.op)] - if type_ == BinOp: + op_type = type(node.op) + if op_type not in legal_operators: + raise TypeError(f'Illegal operator {node.op}') + operator = legal_operators[op_type] + if node_type == BinOp: left, right = eval_node(node.left), eval_node(node.right) return operator(left, right) - elif type_ == UnaryOp: + elif node_type == UnaryOp: operand = eval_node(node.operand) return operator(operand) ```