MCPcopy Create free account
hub / github.com/WhyNotHugo/python-barcode / calculate_checksum

Method calculate_checksum

barcode/upc.py:61–78  ·  view source on GitHub ↗

Calculates the checksum for UPCA/UPC codes :return: The checksum for 'self.upc' :rtype: int

(self)

Source from the content-addressed store, hash-verified

59 return self.upc
60
61 def calculate_checksum(self):
62 """Calculates the checksum for UPCA/UPC codes
63
64 :return: The checksum for 'self.upc'
65 :rtype: int
66 """
67
68 def sum_(x, y):
69 return int(x) + int(y)
70
71 upc = self.upc[0 : self.digits]
72 oddsum = reduce(sum_, upc[::2])
73 evensum = reduce(sum_, upc[1::2])
74 check = (evensum + oddsum * 3) % 10
75 if check == 0:
76 return 0
77
78 return 10 - check
79
80 def build(self) -> list[str]:
81 """Builds the barcode pattern from 'self.upc'

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected