Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39589

Re: Number validation issue

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 <mortenengv@gmail.com>
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; '&gt;&gt;': 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&gt;': 0.20; 'together.': 0.21; 'cc:2**0': 0.23; '&gt;': 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 <CAJ2vgs76po_3JiuqGtLH3b=bP-U1TW-mYYtkxeU-bbx7Z2oHhw@mail.gmail.com>
References <CAJ2vgs5_gYPvMxfBUjs_6QgzUNd4akTvL2p0jV+7E-m8_6xeUw@mail.gmail.com> <CAO+9iGeOQ6jQPfNuG3TSSDK3vFGQVOuWPCgrOcMn+dtJZawj=Q@mail.gmail.com> <CAO+9iGc5bmp9iNveDQ7Bc_LcDDTX6o0rZdr8vHi1aNxYm6go5Q@mail.gmail.com> <CAJ2vgs76po_3JiuqGtLH3b=bP-U1TW-mYYtkxeU-bbx7Z2oHhw@mail.gmail.com>
Date Fri, 22 Feb 2013 17:40:35 +0100
Subject Re: Number validation issue
From Morten Engvoldsen <mortenengv@gmail.com>
To Alec Taylor <alec.taylor6@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2282.1361551242.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Hi,
Just to clear the confusion: i am talking about below part of my code:

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

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 <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.  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 =143
> 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 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..
>
> 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) >= 2 and len(x)<=25 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…
>>
>> 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 22 23
>> > 24 25 26 27 28 29'
>> >
>> > In [2]: [not len(x) >= 2 and len(x)<=25 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 == 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
>> >>
>> >>
>> >>
>> >> --
>> >> http://mail.python.org/mailman/listinfo/python-list
>> >>
>>
>
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Number validation issue Morten Engvoldsen <mortenengv@gmail.com> - 2013-02-22 17:40 +0100

csiph-web