Space Python Loading Python…

Test the error

Write the codeMedium 2 stages

fuel_needed() now refuses a negative burn length with a ValueError. That refusal is part of what the function promises, as much as the arithmetic is, and like the arithmetic it can quietly break.

Write the test that keeps it honest. The hidden tests run your checks against broken versions of the function to see whether they notice.

Write a check that passes only if fuel_needed(-5) raises ValueError: call it in try, set a variable to True in except ValueError:, and assert it after. Then print:

All checks passed

Leave the function as it is. The hidden tests swap it for a version that doesn't raise at all, and one that raises TypeError instead; your check must fail on both.

A check that passes
A check that catches broken versions

Finish stage 1 to unlock this stage.

A function that refuses everything would pass your test so far. Add checks that the message shows the value, "-5" in message, that a 0 s burn is allowed and needs no fuel, and that 40 s needs 500.0 kg. Keep the passed line at the end.

The hidden tests now also try a version that refuses 0, one with a vague message, and one that refuses every length.

Checks that pass
Checks that catch every broken version
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].