Skip to content

Instantly share code, notes, and snippets.

@pletnes
Created December 23, 2022 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pletnes/b7c73290ce09644cf3184b58184fefd0 to your computer and use it in GitHub Desktop.
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)
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