Calculates the checksum for UPCA/UPC codes :return: The checksum for 'self.upc' :rtype: int
(self)
| 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' |