Answer prose round 1: 0 🔴, 9 🟡 (0 misread); docstrings say what the code does, and each fact sits in one place

This commit is contained in:
2026-11-10 22:32:49 +01:00
parent f2fef1d32d
commit 998e295ef9
17 changed files with 19 additions and 22 deletions
+1 -1
View File
@@ -53,11 +53,11 @@ def evaluate(node: ast.AST, values: dict[str, float]) -> float:
divisor = evaluate(right, values)
return evaluate(left, values) / divisor if divisor else math.nan
case ast.BinOp(left, ast.Pow(), right):
# math.pow raises on a negative base with a fractional exponent, zero to a negative power, and overflow; one catch covers all three.
base, exponent = evaluate(left, values), evaluate(right, values)
# A nan from a zero divisor stays nan, though math.pow(1, nan) and math.pow(nan, 0) give 1.
if math.isnan(base) or math.isnan(exponent):
return math.nan
# math.pow raises on a negative base with a fractional exponent, zero to a negative power, and overflow; one catch covers all three.
try:
return math.pow(base, exponent)
except (OverflowError, ValueError):