UPC Validation in Python: Making it Easy
This is turning into a bit of a rabbit hole, but today I noticed that UPCs (Universal Product Codes) have a check digit also. UPCs are the numbers (most of the time accompanied by a bar code) that appear on just about every item and enable those cool scanners at the checkout of your local supermarket.
Interestingly enough, the checkdigit for a UPC-A code (the “normal” UPC) is generated almost like the checkdigit for ISBN-13. Here are the major differences:
- UPCs only have 12 digits (including the checkdigit) versus 13 for ISBN-13
- The checkdigit is calculated by weighting the ODD numbers by 3 (versus the EVEN numbers in ISBN-13)
Other than that, it’s the same process!
…