示例#1
0
def calculate(data: str) -> str:
    """Calculates UPC Check Digits

    Args:
        data: A string of UPC digits

    Returns:
        str: The missing check digit
    """
    return isbn.calculate13(data, "upc")
示例#2
0
test(parity.calculate("01101", False), "011010")

# ISBN-10 Check digit
test(isbn.calculate10("006196436"), "0")
test(isbn.calculate10("190592105"), "5")
test(isbn.calculate10("043942089"), "X")

# Validate ISBN-10
test(isbn.validate10("0205080057"))
test(isbn.validate10("0198526636"))
test(isbn.validate10("1-56619-909-3"))
test(isbn.validate10("01-9323852"), False)
test(isbn.validate10("423423"), False)

# Determine ISBN-13 Check Digit
test(isbn.calculate13("012345678912"), "8")
test(isbn.calculate13("978-1-86197-876"), "9")

test(isbn.calculate13("501234567890", "upc"), "0")
test(isbn.calculate13("03600029145", "upc"), "2")
test(isbn.calculate13("89268500100", "upc"), "3")

# Validate ISBN-13
test(isbn.validate13("0123456789128"))
test(isbn.validate13("9781861978769"))
test(isbn.validate13("9-501101-530003"))
test(isbn.validate13("978-1-56619-909-4"))

# ISBN-10 Missing Digit
# Must be string due to ? and/or X
test(isbn.missing("15688?111X"), "1")