File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -1110,16 +1110,19 @@ def evaluate(expression):
1110
1110
return eval_node(root.body)
1111
1111
1112
1112
def eval_node (node ):
1113
- type_ = type (node)
1114
- if type_ == Num:
1113
+ node_type = type (node)
1114
+ if node_type == Num:
1115
1115
return node.n
1116
- if type_ not in [BinOp, UnaryOp]:
1116
+ if node_type not in [BinOp, UnaryOp]:
1117
1117
raise TypeError (node)
1118
- operator = legal_operators[type (node.op)]
1119
- if type_ == BinOp:
1118
+ op_type = type (node.op)
1119
+ if op_type not in legal_operators:
1120
+ raise TypeError (f ' Illegal operator { node.op} ' )
1121
+ operator = legal_operators[op_type]
1122
+ if node_type == BinOp:
1120
1123
left, right = eval_node(node.left), eval_node(node.right)
1121
1124
return operator(left, right)
1122
- elif type_ == UnaryOp:
1125
+ elif node_type == UnaryOp:
1123
1126
operand = eval_node(node.operand)
1124
1127
return operator(operand)
1125
1128
```
You can’t perform that action at this time.
0 commit comments