Created
December 23, 2022 10:21
-
-
Save pletnes/b7c73290ce09644cf3184b58184fefd0 to your computer and use it in GitHub Desktop.
Python function that validates a vessel's IMO number, using the checksum digit (public domain license)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_imo(num: int): | |
""" | |
Validates IMO number using the checksum digit. | |
""" | |
ns = str(num) | |
sm = sum(d * d2 for d, d2 in zip(map(int, ns[:6]), range(7, -9, -1))) | |
return str(sm)[-1] == ns[-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment