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 add_check_digit(upc_str): | |
""" | |
Returns a 12 digit upc-a string from an 11-digit upc-a string by adding | |
a check digit | |
>>> add_check_digit('02345600007') | |
'023456000073' | |
>>> add_check_digit('21234567899') | |
'212345678992' | |
>>> add_check_digit('04210000526') |
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 upca_to_upce(upca): | |
""" | |
Takes a upc-a code (12 digits), including check digit, | |
as a string and returns upc-e representation. | |
UPC-E representation will be eight digits, including check digit | |
Returns None if no upc-e representation is possible | |
Rules from http://mdn.morovia.com/kb/UPCE-Specification-10634.html | |