from __future__ import division
def calculate_ean_checksum(numbers: list) -> int:
"""
Calculate the checksum digit for a given EAN barcode numbers list.
:param numbers: List of integers representing the EAN barcode numbers.
:type numbers: list[int]
:return: Checksum digit.
:rtype: int
"""
checksum = 0
for i in range(0, len(numbers), 2):
checksum += numbers[i] * (3 - i % 2)
checksum *= 3
checksum = 10 - (checksum % 10)
if checksum == 10:
checksum = 0
return checksum
# Test the function with an example
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
print(f"Checksum digit for input numbers: {calculate_ean_checksum(numbers)}")
In this code snippet, we define a function called calculate_ean_checksum that takes a list of integers as an argument. This list represents the EAN barcode numbers. Inside the function, we calculate the checksum by summing each even and odd number multiplied by a specific weight, and then multiply the result by 3 and find the remainder after dividing by 10. Finally, we return the checksum value.
In the example, we tested the function with a list of 10 numbers, which is typical for a EAN-13 barcode. The result will either be a 0 or a number between 1 and 9. If the result is 10, it is converted to 0. You can replace the test input numbers with your input list to verify the checksum.