From 01ad4fe589647b11e378152f0454ad3e763c6b83 Mon Sep 17 00:00:00 2001 From: guilhermenevesxyz Date: Sat, 20 Aug 2022 20:22:12 +0100 Subject: [PATCH] fixing 'jonasbugas' --- pobrelanglib/pl_parser.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pobrelanglib/pl_parser.py b/pobrelanglib/pl_parser.py index 5ff5965..da04a9f 100644 --- a/pobrelanglib/pl_parser.py +++ b/pobrelanglib/pl_parser.py @@ -22,9 +22,11 @@ def extract_expression(token: str) -> str: return token.split(":", 1)[1] def parse_math(expr: str, module: Module) -> str: - for var, val in module.variables.items(): - expr = expr.replace(var, val) - + sorted_vars = sorted(module.variables.keys(), key=len) + + for var in reversed(sorted_vars): + expr = expr.replace(var, module.variables[var]) + return str(float(eval(expr))) def create_variable(type: str, name: str, value: str, module: Module) -> None: