Travel Weather Planner has incomplete and inaccurate tests and hints
Describe the Issue
The Build a Travel Weather Planner lab has the following test and hint problems.
Rain-dependent behavior is not distinguished by the tests
run_case( { "distance_mi": 2, "is_raining": True, "has_bike": False, "has_car": True, "has_ride_share_app": True }, "False" )run_case( { "distance_mi": 2, "is_raining": False, "has_bike": True, "has_car": False, "has_ride_share_app": False }, "True" )run_case( { "distance_mi": 12, "is_raining": False, "has_bike": False, "has_car": False, "has_ride_share_app": True }, "True" )run_case( { "distance_mi": 12, "is_raining": False, "has_bike": True, "has_car": True, "has_ride_share_app": False }, "True" )Replacing
print(has_bike and not is_raining)withprint(has_bike)passes all nine behavioral tests, although a rainy two-mile trip with a bike must printFalse. Independently, replacing the final output withprint((has_car or has_ride_share_app) and not is_raining)also passes all nine tests, although rain must not prevent a long trip when a car or ride-share app is available.Suggested fix: Add output checks for these combinations, keeping the existing cases:
distance_miis_raininghas_bikehas_carhas_ride_share_appPrinted result 2TrueTrueFalseFalseFalse12TrueFalseTrueFalseTrue12TrueFalseFalseTrueTrueThe boolean-operator requirement is missing from the user stories, and its test accepts other unary operators
You should use at least one boolean operator (`and`, `or`, or `not`) in your code.The user stories require conditional statements and specific outcomes, but never require the
and,or, ornotkeywords. The requirement in this hint should also appear in the user stories so learners know they must use at least one boolean operator.The test also accepts arithmetic unary operators:
bool_ops = [ node for node in ast.walk(tree) if isinstance(node, (ast.BoolOp, ast.UnaryOp)) ] assert len(bool_ops) >= 1The assertion passes for
x = -1, which contains none of the three operators named in the hint.ast.UnaryOpalso represents unary plus, unary minus, and bitwise inversion; see the Python AST reference.Suggested fix: Add a user story explicitly requiring at least one boolean operator (
and,or, ornot). Update the test to acceptast.BoolOpor anast.UnaryOponly when itsopisast.Not:bool_ops = [ node for node in ast.walk(tree) if isinstance(node, ast.BoolOp) or (isinstance(node, ast.UnaryOp) and isinstance(node.op, ast.Not)) ] assert len(bool_ops) >= 1Verify that code using
and,or, ornotpasses this test, while code whose only operators are unary minus (-1), unary plus (+1), or bitwise inversion (~1) fails it.The distance type assertion accepts booleans
({ test: () => runPython(`assert isinstance(distance_mi, (int, float))`) })The assertion accepts
TrueandFalseas distances becauseisinstance(True, (int, float))evaluates toTrue. This does not enforce the distinction between a numeric distance and the four boolean flags in the user stories.Suggested fix: Exclude booleans from the numeric type check:
({ test: () => runPython(`assert isinstance(distance_mi, (int, float)) and not isinstance(distance_mi, bool)`) })Incorrect no/nor construction
When the distance is greater than `6` miles and no car nor a ride share app is available, the program should print `False`.The sentence mixes
nowithnorand inserts an unmatched article before the second noun.Suggested fix: Use the following hint:
When the distance is greater than
6miles and neither a car nor a ride-share app is available, the program should printFalse.
Affected Pages
Expected behavior
- The tests distinguish rainy and dry conditions where they affect the result. A rainy trip between one and six miles prints
Falseeven when a bike is available. Trips over six miles printTruewhen a car or ride-share app is available, regardless of rain. - The user stories explicitly require at least one boolean operator (
and,or, ornot). The test accepts those operators without counting unary plus, unary minus, or bitwise inversion. - The distance type test accepts numeric distances and rejects boolean values.
- The final hint uses a grammatical construction to describe the absence of both a car and a ride-share app.
Source: freeCodeCamp/freeCodeCamp