Math-Solver / app_logic.py
HariHaran9597
fix: make answer comparison explicit and cautious
4ee5f09
Raw History Blame Contribute Delete
401 Bytes
import re
def extract_answer(text):
"""Return only an explicitly marked final answer, never a number from reasoning."""
if not text or "####" not in text:
return None
final = text.rsplit("####", 1)[-1].strip()
match = re.search(r"(?<![A-Za-z0-9])(-?\$?\d[\d,]*(?:\.\d+)?)(?![A-Za-z0-9])", final)
return match.group(1).replace(",", "").replace("$", "") if match else None