Command Palette

Search for a command to run...

Hectal
Phase 10: Type Hints and Modern Python
Python · Exercise 1 of 5Next
Beginner

Annotate a function

The function scale multiplies every number in a list by a factor. It has no type hints yet. Add them: values is a list[float], factor is a float, label is a str or None (default None), and the function returns a list[float].

Write each hint as name: type and keep = None after the hint for label. Do not change what the function does. The last line, already in the starter, prints the result for [1.0, 2.0] and 2.0.

What Check tests

  1. values is hinted list[float]
  2. factor is hinted float
  3. label is hinted str | None and still defaults to None
  4. The return value is hinted list[float]
  5. The behaviour is unchanged

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.