IBAN Validation (mod 97)

medium
Unit 21 · Immutability0/3 to milestone

An IBAN is validated by moving the first four characters to the end, replacing each letter with two digits (A = 10 ... Z = 35), and checking the resulting number mod 97 equals 1.

Implement valid_iban(s):

  • ignore spaces; letters may be any case
  • the country code (first 2 chars) must be letters and the check digits (next 2) must be digits
  • the length must match LENGTHS[country] for known countries (unknown countries are invalid)
  • compute the mod 97 piece by piece without building one giant integer (process a few digits at a time)

Also implement format_iban(s): upper case, grouped in fours separated by spaces.

#validation#banking#big-integers2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
IBAN Validation (mod 97) · TechGradify