No special case: version numbers
Why it matters A bug report names one input. The quickest patch handles that input. The bug usually lives in a rule that is wrong for many inputs, and patches pile up around it.
A desktop app asks the update server for the latest release and offers it if it is newer than the one installed. This is the code, and two bug reports from the same week:
def is_newer(a, b):
return a > b
# Bug 1: is_newer("1.10", "1.9") is False, so nobody on 1.9 is offered 1.10.
# Bug 2: is_newer("2.0", "2") is True, so people on 2 are told to update to the same release.Release numbers are written by people and by several build tools. Some write 2, some 2.0.0; one pads with zeros (2026.01.05 is the same release as 2026.1.5); the plug-in builds add a fourth, fifth or sixth part.
In this problem special-case patches are banned. Fix the rule, not the reported inputs.
Rewrite is_newer(a, b) to return True if release a is later than release b, and False if it is earlier or the same release. A version is 1 to 6 whole numbers joined by dots (no letters, no spaces). Compare them as numbers, part by part from the left; leading zeros do not matter (01 is 1), and a missing part counts as 0, so 2, 2.0 and 2.0.0 are one release. Rule: no if statement whose condition contains a written-out number or string (like == "2.0" or == 0) and whose block returns. Conditions that compare your own values with each other, such as if x != y: return x > y, are fine, and so is any if that only assigns.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.