def calc_check_digit(value):
    """calculate check digit, they are the same for both UPCA and UPCE"""
    check_digit=0
    odd_pos=True
    for char in str(value)[::-1]:
        if odd_pos:
            check_digit+=int(char)*3
        else:
            check_digit+=int(char)
        odd_pos=not odd_pos #alternate
    check_digit=check_digit % 10
    check_digit=10-check_digit
    check_digit=check_digit % 10
    return check_digit
calculate check digit, they are the same for both UPCA and UPCE
recipes/Python/528911_Barcodes__Convert_UPCE_to_UPCA/recipe-528911.py