Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39577 > unrolled thread
| Started by | Morten Engvoldsen <mortenengv@gmail.com> |
|---|---|
| First post | 2013-02-22 16:09 +0100 |
| Last post | 2013-02-22 16:09 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
Number validation issue Morten Engvoldsen <mortenengv@gmail.com> - 2013-02-22 16:09 +0100
| From | Morten Engvoldsen <mortenengv@gmail.com> |
|---|---|
| Date | 2013-02-22 16:09 +0100 |
| Subject | Number validation issue |
| Message-ID | <mailman.2272.1361545770.2939.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
Hi ,
I have wrote the below code to validate a number using modulus 10 and 11:
def is_valid_number(checknum, mod):
if mod == 10:
if not len(checknum) >= 2 and len(checknum) <=25:
return False
number = tuple(int(i) for i in reversed(str(checknum)) )
return (sum(int(num) * 2 for num in number[1::2]) % 10) == 0
elif mod == 11:
if not len(checknum)!= 11:
return False
weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]
return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) ==
0
is_valid_number("12345678217", 10)
The above code is able to validate 25 length number for modulus 10 , but
for modulus 11 i have done the validation only for 11 digit, Since for
modulus 11 the weight should be in
.............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 in this format.
Could you please let me know how can i validate the 25 length number for
modulus 11 with weight ...............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,
2, 1 in this format.
Regards,
Morten
Back to top | Article view | comp.lang.python
csiph-web