Skip to content

Instantly share code, notes, and snippets.

@Barakat
Created February 27, 2017 10:50
Show Gist options
  • Select an option

  • Save Barakat/d144f16d7192284a5ded3b24a2d082ed to your computer and use it in GitHub Desktop.

Select an option

Save Barakat/d144f16d7192284a5ded3b24a2d082ed to your computer and use it in GitHub Desktop.
Compute the checksum of EAN-13 barcodes
def compute_ean13_checksum(barcode):
assert len(barcode) == 12 and barcode.isdigit()
return (10 - sum(int(i) * j for i, j in zip(barcode, (1, 3) * 6)) % 10) % 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment