Hi,<br>Just to make it more clear: I am looking for how to generate the weight in :<br>1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7..  format for any length of number instead of <br> <br>weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]<br>
<br>only for fixed digit. <br><br>My below code can check only for 9 digit, so if we provide a number of more than 9 digit, it is not able to check that number. Hope, this makes clear what i am looking for...<br><br><br><div class="gmail_quote">
On Fri, Feb 22, 2013 at 6:27 PM, Morten Engvoldsen <span dir="ltr"><<a href="mailto:mortenengv@gmail.com" target="_blank">mortenengv@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>My below code is wrong :<div class="im"><br><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) ==0 <br><br></div>it works for 9 digit number , not 11 digit number, so i have changed the code and sending again with correct code with valid number:<br>

<br>def is_valid_number(checknum):<br>    weights = [3, 2, 7, 6, 5, 4, 3, 2, 1]<div class="im"><br>    return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) == 0<br><br></div>is_valid_number("123456785")<br>
<br>This code validate this 9 digit number "123456785" with below algorithm:<div class="im"><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></div>So i am looking for solution how i can change this code to validate with weight 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... from right to left for any length of number. This code validate only 9 digit number.<br>

<br>Sorry for inconvience :(<br><br><br>
</blockquote></div><br>