Hi,<br>Thanks for your reply.<br><br>Here in your code i think you didn't multiply the given number with the weight i have mentioned. The each digit of the given number should multiply with weight ...............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 in this format. That is in detail:<br>
<br>To verify the number use the following weights from right to left:<br>1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7...<br>Multiply each digit by its corresponding weight. Add the results together. For the number to be correct the<br>
total must be divisible by 11.<br>Field with control digit 1 2 3 4 5 6 7 8 5<br>Weight 3 2 7 6 5 4 3 2 1<br>Produce +3 +4 +21 +24 +25 +24 +21 +16 +5 =143<br>The sum must be divisible by 11 (143 divided by 11 leaves a remainder of 0).<br>
<br>So my code has validated only the length of 11 digit. So i am looking for 'n' length of number should be validated with weight ...............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 from left to right..<br>
<br>Thanks again ...<br><br><br><div class="gmail_quote">On Fri, Feb 22, 2013 at 4:33 PM, Alec Taylor <span dir="ltr"><<a href="mailto:alec.taylor6@gmail.com" target="_blank">alec.taylor6@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Whoops, my mistake:<br>
<br>
In [5]: [not len(x) >= 2 and len(x)<=25 for x in [str(y) for y in xrange(30)]]<br>
Out [5]: [True]*10, [False]*20<br>
<br>
But still, I'm guessing that's not the result you were looking for…<br>
<div class="HOEnZb"><div class="h5"><br>
On Sat, Feb 23, 2013 at 2:30 AM, Alec Taylor <<a href="mailto:alec.taylor6@gmail.com">alec.taylor6@gmail.com</a>> wrote:<br>
> Out[1]: '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23<br>
> 24 <a href="tel:25%2026%2027%2028%2029" value="+12526272829">25 26 27 28 29</a>'<br>
><br>
> In [2]: [not len(x) >= 2 and len(x)<=25 for x in _]<br>
> Out[2]: [True]*79 # shorthand to prevent spam<br>
><br>
><br>
> I trust you can see the error now!<br>
><br>
> On Sat, Feb 23, 2013 at 2:09 AM, Morten Engvoldsen <<a href="mailto:mortenengv@gmail.com">mortenengv@gmail.com</a>> wrote:<br>
>> Hi ,<br>
>> I have wrote the below code to validate a number using modulus 10 and 11:<br>
>><br>
>> def is_valid_number(checknum, mod):<br>
>> if mod == 10:<br>
>> if not len(checknum) >= 2 and len(checknum) <=25:<br>
>> return False<br>
>> number = tuple(int(i) for i in reversed(str(checknum)) )<br>
>> return (sum(int(num) * 2 for num in number[1::2]) % 10) == 0<br>
>> elif mod == 11:<br>
>> if not len(checknum)!= 11:<br>
>> return False<br>
>> weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]<br>
>> return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) ==<br>
>> 0<br>
>><br>
>> is_valid_number("12345678217", 10)<br>
>><br>
>> The above code is able to validate 25 length number for modulus 10 , but for<br>
>> modulus 11 i have done the validation only for 11 digit, Since for modulus<br>
>> 11 the weight should be in<br>
>> .............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 in this format.<br>
>><br>
>> Could you please let me know how can i validate the 25 length number for<br>
>> modulus 11 with weight ...............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,<br>
>> 2, 1 in this format.<br>
>><br>
>> Regards,<br>
>> Morten<br>
>><br>
>><br>
>><br>
>> --<br>
>> <a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
>><br>
</div></div></blockquote></div><br>