Path: csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'elif': 0.04; "'n'": 0.09; '22,': 0.09; '[2]:': 0.09; 'len(x)': 0.09; 'cc:addr:python-list': 0.10; 'advance': 0.10; 'def': 0.10; 'sat,': 0.15; '>>': 0.16; '0).': 0.16; 'again..': 0.16; 'guessing': 0.16; 'int(x)': 0.16; 'left:': 0.16; 'received:74.125.82.46': 0.16; 'shorthand': 0.16; 'still,': 0.16; 'subject:issue': 0.16; 'wrote:': 0.17; 'skip:i 40': 0.17; 'feb': 0.19; 'email addr:gmail.com>': 0.20; 'together.': 0.21; 'cc:2**0': 0.23; '>': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'wrote': 0.26; 'am,': 0.27; 'prevent': 0.27; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'reply.': 0.28; 'leaves': 0.29; 'mod': 0.29; 'url:mailman': 0.29; "i'm": 0.29; 'fri,': 0.30; 'error': 0.30; 'code': 0.31; 'url:python': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'received:74.125.82': 0.33; 'subject:Number': 0.33; 'code:': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'thanks': 0.34; 'clear': 0.35; 'false': 0.35; 'skip:. 20': 0.35; 'pm,': 0.35; 'add': 0.36; 'but': 0.36; 'received:74.125': 0.36; 'url:org': 0.36; "didn't": 0.36; 'should': 0.36; 'subject:: ': 0.38; 'url:mail': 0.40; 'think': 0.40; 'your': 0.60; 'skip:n 10': 0.63; 'here': 0.65; 'charset:windows-1252': 0.65; 'results': 0.65; 'total': 0.65; 'validate': 0.65; 'talking': 0.66; 'sum': 0.66; '11.': 0.81; '11:': 0.84; '2013': 0.84; '2:30': 0.84; 'alec': 0.84; 'multiply': 0.84; 'divided': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=uEIXqWf++yUp4DxxEA1mZ/WvzqZOjPFCwinQ+lV7egc=; b=pwN8YxB3mraMcLJiFlKUAp/Zma5yI2X957KfX0rKo9zdNXrrQt9y9RSka0ToG8RUJA v/0ibsLJS0btyu7zMd8Ug33B2vlT0RTVnWzNNB2YVBxg2wg9JVW2fHlMPaUSFP3Kum3n 8Hu9mrJOEk2puoxr95lgxrp1XWy+o3qdOJ5QRLANYMKKt42goRNEgvmHlD2tlKtHRx6g 61MKfkheZ2TjqWd6nBVCTRc74S4aq+w3ePxdew7uc0euzJdJoRdr6hdZL/hykrXnRuv/ YRwcIfFXBokgue5PIqjioFXwc9j2ae7ztJHJXndGkBNx1pjhjaNIlPvp+oGgD39suuCU Yryg== MIME-Version: 1.0 X-Received: by 10.180.79.227 with SMTP id m3mr14915wix.12.1361551235719; Fri, 22 Feb 2013 08:40:35 -0800 (PST) In-Reply-To: References: Date: Fri, 22 Feb 2013 17:40:35 +0100 Subject: Re: Number validation issue From: Morten Engvoldsen To: Alec Taylor Content-Type: multipart/alternative; boundary=14dae9cc9f96bfa97d04d652d98e Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 247 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361551242 news.xs4all.nl 6865 [2001:888:2000:d::a6]:48710 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39589 --14dae9cc9f96bfa97d04d652d98e Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hi, Just to clear the confusion: i am talking about below part of my code: elif mod =3D=3D 11: >> if not len(checknum)!=3D 11: >> return False >> weights =3D [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] >> return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11) =3D=3D0 for which i am looking for solution that it should validate the 'n' length of number with weight ...............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 in this format from left to right. Thanks in advance again.. On Fri, Feb 22, 2013 at 5:32 PM, Morten Engvoldsen wr= ote: > Hi, > Thanks for your reply. > > 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: > > To verify the number use the following weights from right to left: > 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... > Multiply each digit by its corresponding weight. Add the results together= . > For the number to be correct the > total must be divisible by 11. > Field with control digit 1 2 3 4 5 6 7 8 5 > Weight 3 2 7 6 5 4 3 2 1 > Produce +3 +4 +21 +24 +25 +24 +21 +16 +5 =3D143 > The sum must be divisible by 11 (143 divided by 11 leaves a remainder of > 0). > > So my code has validated only the length of 11 digit. So i am looking fo= r > '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.. > > Thanks again ... > > > > On Fri, Feb 22, 2013 at 4:33 PM, Alec Taylor wrot= e: > >> Whoops, my mistake: >> >> In [5]: [not len(x) >=3D 2 and len(x)<=3D25 for x in [str(y) for y in >> xrange(30)]] >> Out [5]: [True]*10, [False]*20 >> >> But still, I'm guessing that's not the result you were looking for=85 >> >> On Sat, Feb 23, 2013 at 2:30 AM, Alec Taylor >> wrote: >> > 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 >> > 24 25 26 27 28 29' >> > >> > In [2]: [not len(x) >=3D 2 and len(x)<=3D25 for x in _] >> > Out[2]: [True]*79 # shorthand to prevent spam >> > >> > >> > I trust you can see the error now! >> > >> > On Sat, Feb 23, 2013 at 2:09 AM, Morten Engvoldsen < >> mortenengv@gmail.com> wrote: >> >> Hi , >> >> I have wrote the below code to validate a number using modulus 10 and >> 11: >> >> >> >> def is_valid_number(checknum, mod): >> >> if mod =3D=3D 10: >> >> if not len(checknum) >=3D 2 and len(checknum) <=3D25: >> >> return False >> >> number =3D tuple(int(i) for i in reversed(str(checknum)) ) >> >> return (sum(int(num) * 2 for num in number[1::2]) % 10) =3D= =3D 0 >> >> elif mod =3D=3D 11: >> >> if not len(checknum)!=3D 11: >> >> return False >> >> weights =3D [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] >> >> return (sum(w * int(x) for w, x in zip(weights, checknum)) % >> 11) =3D=3D >> >> 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 >> >> >> >> >> >> >> >> -- >> >> http://mail.python.org/mailman/listinfo/python-list >> >> >> > > --14dae9cc9f96bfa97d04d652d98e Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hi,
Just to clear the confusion: i am talking about below part of my cod= e:

elif mod =3D=3D 11:
>> =A0 =A0 =A0 =A0 if not len(checknum)!=3D 11:
>> =A0 =A0 =A0 =A0 =A0 =A0 return False
>> =A0 =A0 =A0 =A0 weights =3D [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]
>> =A0 =A0 =A0 =A0 return (sum(w * int(x) for w, x in zip(weights, ch= ecknum)) % 11) =3D=3D0

for which i am looking for solution that it = should validate the 'n' length of number with weight ..............= .4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 =A0in this format from left to r= ight.

Thanks in advance again..

On Fri, Feb= 22, 2013 at 5:32 PM, Morten Engvoldsen <mortenengv@gmail.com> wrote:
Hi,
Thanks for your reply.

Here in= your code i think you didn't multiply the given number with the weight= i have mentioned.=A0 The each digit of the given number should multiply wi= th weight ...............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 =A0in th= is format. That is in detail:

To verify the number use the following weights from right to left:
1= , 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7...
Multiply each = digit by its corresponding weight. Add the results together. For the number= to be correct the
total must be divisible by 11.
Field with control digit 1 2 3 4 5 6 7 8 = 5
Weight 3 2 7 6 5 4 3 2 1
Produce +3 +4 +21 +24 +25 +24 +21 +16 +5 = =3D143
The sum must be divisible by 11 (143 divided by 11 leaves a remai= nder of 0).

So my code has validated only the length of 11 digit.=A0 So i am lookin= g for 'n' length of number should be validated with weight=A0 ....= ...........4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1=A0=A0 from left to rig= ht..

Thanks again ...



On Fri, Feb 22, 2013 at 4:33 PM, Alec Taylor <alec.taylor6@gmail.com> wrote:
Whoops, my mistake:

In [5]: [not len(x) >=3D 2 and len(x)<=3D25 for x in [str(y) for y in= xrange(30)]]
Out [5]: [True]*10, [False]*20

But still, I'm guessing that's not the result you were looking for= =85

On Sat, Feb 23, 2013 at 2:30 AM, Alec Taylor <alec.taylor6@gmail.com> wrote:
> Out[1]: '0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2= 2 23
> 24 25 26 27 28 29'
>
> In [2]: [not len(x) >=3D 2 and len(x)<=3D25 for x in _]
> Out[2]: [True]*79 # shorthand to prevent spam
>
>
> I trust you can see the error now!
>
> On Sat, Feb 23, 2013 at 2:09 AM, Morten Engvoldsen <mortenengv@gmail.com> wro= te:
>> Hi ,
>> I have wrote the below code to validate a number using modulus 10 = and 11:
>>
>> def is_valid_number(checknum, mod):
>> =A0 =A0 if mod =3D=3D 10:
>> =A0 =A0 =A0 =A0 if not len(checknum) >=3D 2 and len(checknum) &= lt;=3D25:
>> =A0 =A0 =A0 =A0 =A0 =A0 return False
>> =A0 =A0 =A0 =A0 number =3D tuple(int(i) for i in reversed(str(chec= knum)) )
>> =A0 =A0 =A0 =A0 return (sum(int(num) * 2 for num in number[1::2]) = % 10) =3D=3D 0
>> =A0 =A0 elif mod =3D=3D 11:
>> =A0 =A0 =A0 =A0 if not len(checknum)!=3D 11:
>> =A0 =A0 =A0 =A0 =A0 =A0 return False
>> =A0 =A0 =A0 =A0 weights =3D [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]
>> =A0 =A0 =A0 =A0 return (sum(w * int(x) for w, x in zip(weights, ch= ecknum)) % 11) =3D=3D
>> 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, =A0Since = for modulus
>> 11 the weight should be in
>> .............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 =A0in this= format.
>>
>> Could you please let me know how can i validate the 25 length numb= er for
>> modulus 11 with weight ...............4,3,2,7,6, 5, 4, 3, 2, 7, 6,= 5, 4, 3,
>> 2, 1 =A0in this format.
>>
>> Regards,
>> Morten
>>
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>


--14dae9cc9f96bfa97d04d652d98e--