Command Palette

Search for a command to run...

Hectal
Phase 6: Modules, Packages and Projects
Python · Exercise 2 of 5 PreviousNext
Intermediate

Compare versions as numbers

Write parse_version(text) that turns "2.10.0" into the tuple (2, 10, 0).

Write newest(versions) that returns the highest version string from a list, comparing as numbers (not as text).

Print newest(["2.9.0", "2.10.0", "2.1.5"]).

What Check tests

  1. parse_version("2.10.0") is (2, 10, 0)
  2. newest picks 2.10.0 over 2.9.0
  3. newest(["1.0.0"]) returns the only item
  4. Versions with different numbers of parts compare correctly
  5. A two-digit major version beats a one-digit one
  6. The program prints 2.10.0

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.