Created
February 27, 2017 10:50
-
-
Save Barakat/d144f16d7192284a5ded3b24a2d082ed to your computer and use it in GitHub Desktop.
Compute the checksum of EAN-13 barcodes
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 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