From 09979d9ada08c2163ee12d9abdf4f44950b8af1c Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Mon, 23 Feb 2026 22:15:54 +0530 Subject: [PATCH] fix(curriculum): add test for falsy value in lab travel weather planner (#65986) --- .../694acade1d4afdbce71e5840.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/curriculum/challenges/english/blocks/lab-travel-weather-planner/694acade1d4afdbce71e5840.md b/curriculum/challenges/english/blocks/lab-travel-weather-planner/694acade1d4afdbce71e5840.md index 993f4bf2fd3..ed8b22e7419 100644 --- a/curriculum/challenges/english/blocks/lab-travel-weather-planner/694acade1d4afdbce71e5840.md +++ b/curriculum/challenges/english/blocks/lab-travel-weather-planner/694acade1d4afdbce71e5840.md @@ -146,6 +146,65 @@ You should use the `print()` function to display the result. ({ test: () => runPython(`assert _Node(_code).block_has_call("print")`) }) ``` +When `distance_mi` is a falsy value, the program should print `False`. + +```js +({ test: () => runPython(` +import ast, io, contextlib + +VARIABLES = { + "distance_mi", + "is_raining", + "has_bike", + "has_car", + "has_ride_share_app" +} + +def run_case(env, expected): + tree = ast.parse(_code) + + tree.body = [ + node for node in tree.body + if not ( + isinstance(node, ast.Assign) + and isinstance(node.targets[0], ast.Name) + and node.targets[0].id in VARIABLES + ) + ] + + clean_code = compile(tree, "", "exec") + + buffer = io.StringIO() + with contextlib.redirect_stdout(buffer): + exec(clean_code, env) + + assert buffer.getvalue().strip() == expected + + +run_case( + { + "distance_mi": 0, + "is_raining": False, + "has_bike": True, + "has_car": True, + "has_ride_share_app": True + }, + "False" +) + +run_case( + { + "distance_mi": 0.0, + "is_raining": False, + "has_bike": True, + "has_car": True, + "has_ride_share_app": True + }, + "False" +) +`) }) +``` + When the distance is `1` mile or less and it is not raining, the program should print `True`. ```js