[Tutor] Python
Dennis Lee Bieber
wlfraed at ix.netcom.com
Fri Oct 22 13:33:31 EDT 2021
o/~ Talking to myself in public o/~
On Thu, 21 Oct 2021 13:16:23 -0400, Dennis Lee Bieber
<wlfraed at ix.netcom.com> declaimed the following:
>On Wed, 20 Oct 2021 18:35:19 -0400, Vanshika Sadhwani <monvansha at gmail.com>
>declaimed the following:
>
> I'm not going to crawl through all of your code but will comment on one
>facet.
>
Okay, I lied -- I did look further.
You must have some specification for the algorithms to apply to each
"code type", which you have not shown us.
I mention this as your code for "basic" and "positional" codes compute
the exact same result; there is no difference other than using sum() in
one, and a for/+= loop in the other.
Your code for UPC does not take into account that a valid UPC
(universal product code -- so "UPC code" is redundant) is exactly 12 digits
in length (a small modification to the algorithm would also allow it to
handle 13-digit European Article Number (EAN) codes which are basically a
UPC with a prefix country/zone designator).
Part of your code seems to mix /validation/ of a code with the logic
required to generate a check digit. That is, one would process an 11-digit
"UPC", take the modulo 10, and (for non-zero) do that "check=10-mod" to
create the 12th digit for the UPC. Most algorithms that use "check=10-mod"
logic are meant to be verified by the taking the sum (accounting for any
position based multipliers) of the entire code modulo 10 and getting a 0 if
the code is valid.
https://www.codeproject.com/Articles/459507/Identification-numbers-and-check-digit-algorithms
For UPC...
"""
Verification: To verify the number, we can use this formula:
[3.d1 + 1.d2 + 3.d3 + 1.d4 + 3.d5 + 1.d6 + 3.d7 + 1.d8 + 3.d9 + 1.d10 +
3.d11 + 1.d12] mod10 = 0
Here d1, d2, d3...etc. are the digits. Starting from the left, we multiply
the digits with 3 and 1 alternatively.
Example: 036000 291452
3x0 + 1x3 + 3x6 + 1x0 + 3x0 + 1x0 + 3x2 + 1x9 + 3x1 + 1x4 + 3x5 + 1x2
=> 0+3+18+0+0+0+9+3+4+15+2 => 60 => 60mod10 => 0.
Hence the number is verified:
"""
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
More information about the Tutor
mailing list