Skip to content

Instantly share code, notes, and snippets.

@bentappin
Created June 1, 2011 21:41
Show Gist options
  • Save bentappin/1003397 to your computer and use it in GitHub Desktop.
Save bentappin/1003397 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