Command Palette

Search for a command to run...

Hectal
Phase 11: Testing and Code Quality
Python · Exercise 5 of 6 PreviousNext
Intermediate

Document a function with doctest examples

clamp(value, low, high) returns value limited to the range from low to high. Its implementation is done.

Write the docstring examples: at least three >>> examples with the expected output underneath. Include a value inside the range, one below low, and one above high. Write each expected output exactly as Python would print it: the number 5 prints as 5, with no quotes.

The runner code at the bottom runs your examples and prints how many were tried and how many failed. All of them must pass.

What Check tests

  1. At least 3 examples were run
  2. No example fails
  3. The docstring has at least 3 >>> lines
  4. clamp behaves correctly

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.