Skip to content

Instantly share code, notes, and snippets.

@benhoyle
Created May 1, 2018 09:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benhoyle/13ffb941f6d146e951723fb2ab57a80a to your computer and use it in GitHub Desktop.
Save benhoyle/13ffb941f6d146e951723fb2ab57a80a to your computer and use it in GitHub Desktop.
Calculate EPO Check Digit given the application number as a string
def calculate_checkdigit(appln_number):
"""Calculate EPO checkdigit."""
def digits_of(n):
return [int(d) for d in str(n)]
digits = digits_of(appln_number)
even_digits = digits[-1::-2]
odd_digits = digits[-2::-2]
checksum = 0
checksum += sum(odd_digits)
for d in even_digits:
checksum += sum(digits_of(d*2))
check_digit = 10 - (checksum % 10)
if check_digit == 10:
check_digit = 0
return check_digit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment