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


Groups > comp.lang.python > #39587

Re: Number validation issue

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!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.013
X-Spam-Evidence '*H*': 0.97; '*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; 'def': 0.10; 'sat,': 0.15; '&gt;&gt;': 0.16; '0).': 0.16; 'guessing': 0.16; 'int(x)': 0.16; 'left:': 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; '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; 'hi,': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'thanks': 0.34; '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; '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=WCIjAffev4s7T89oVbrw1INUS0iPpRkbWuUV4b07MDA=; b=bWCv5KJis39pZ84I/RyXK3Vs77zsupfsuGRA+S0e9k2klYj+ZsPugX771E0XxJDYjg /NrQbsh7rP1c/2iAsLjRH7EJlPlIRz/f0lTZAa8/LQAG/ZpsKbG0qVXriA047G7yVXdx y/NPgFa0UoDH4hQpk6HTFGbC3RVCzxp4ZhJv1lj8FHDBla1iSrhQaIyuQtDlgWP68Ly9 pmrOH7ViQ7QTF1w59ISEVUp5v0j/zrOrR4WvQEnNWQ2N9BZgpgVCgH9a/kF3dfFZej5V xAeiRiPHNLFCr18as6Hhiro6Pi9sUjhfmRM7VkNWb4ZHea/CSL7OPjcalrKn46rOp8H5 IgCw==
MIME-Version 1.0
X-Received by 10.194.19.97 with SMTP id d1mr4646169wje.52.1361550769871; Fri, 22 Feb 2013 08:32:49 -0800 (PST)
In-Reply-To <CAO+9iGc5bmp9iNveDQ7Bc_LcDDTX6o0rZdr8vHi1aNxYm6go5Q@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>
Date Fri, 22 Feb 2013 17:32:49 +0100
Subject Re: Number validation issue
From Morten Engvoldsen <mortenengv@gmail.com>
To Alec Taylor <alec.taylor6@gmail.com>
Content-Type multipart/alternative; boundary=047d7b5d9a6dfb6d0604d652bdf8
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.2280.1361550771.2939.python-list@python.org> (permalink)
Lines 200
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361550771 news.xs4all.nl 6852 [2001:888:2000:d::a6]:42693
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39587

Show key headers only | View raw


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

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:32 +0100

csiph-web