Skip to content

Instantly share code, notes, and snippets.

@Apkawa
Forked from bentappin/gist:1003397
Created February 9, 2012 15:26
Show Gist options
  • Save Apkawa/1780668 to your computer and use it in GitHub Desktop.
Save Apkawa/1780668 to your computer and use it in GitHub Desktop.
Generate checksum for a barcode/ean-13
def calc_ean_13_checksum(ean):
import math
sum = 0
for x, c in enumerate(str(ean)[::-1]):
if (x+1) % 2 == 0:
sum += int(c)
else:
sum += int(c) * 3
return int(math.ceil(sum / 10.0) * 10) - sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment