| Алмаз Сейтхазин (КФ МГУ, кафедра НДС) EvalFormulae 4335 | Барлыбай Мади, 311/312 группа EvalFormulae 4380 | ||||
|---|---|---|---|---|---|
| t | 1 | import ast | t | 1 | import ast |
| 2 | 2 | ||||
| 3 | def evalform(formula, *args): | 3 | def evalform(formula, *args): | ||
| 4 | tree = ast.parse(formula, mode='eval') | 4 | tree = ast.parse(formula, mode='eval') | ||
| 5 | variables = sorted({node.id for node in ast.walk(tree) if isinstance | 5 | variables = sorted({node.id for node in ast.walk(tree) if isinstance | ||
| > | (node, ast.Name)}) | > | (node, ast.Name)}) | ||
| 6 | locals_dict = dict(zip(variables, args)) | 6 | locals_dict = dict(zip(variables, args)) | ||
| 7 | return eval(formula, {}, locals_dict) | 7 | return eval(formula, {}, locals_dict) | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||