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


Groups > comp.lang.python > #39603

Re: Number validation issue

References (1 earlier) <CAO+9iGeOQ6jQPfNuG3TSSDK3vFGQVOuWPCgrOcMn+dtJZawj=Q@mail.gmail.com> <CAO+9iGc5bmp9iNveDQ7Bc_LcDDTX6o0rZdr8vHi1aNxYm6go5Q@mail.gmail.com> <CAJ2vgs76po_3JiuqGtLH3b=bP-U1TW-mYYtkxeU-bbx7Z2oHhw@mail.gmail.com> <CAJ2vgs4YvQ+RcKMjEnSimRE3pv3QYbuHuSeHfnU703w1QJr5Ew@mail.gmail.com> <CAJ2vgs5oX0Oxt++K8v8qHdB46ewpoLKQ9QxQX5P3u_NvypFM7g@mail.gmail.com>
Date 2013-02-22 19:27 +0100
Subject Re: Number validation issue
From Morten Engvoldsen <mortenengv@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2292.1361557644.2939.python-list@python.org> (permalink)

Show all headers | View raw


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

Hi,
Just to make it more clear: I am looking for how to generate the weight in :
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

weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]

only for fixed digit.

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...


On Fri, Feb 22, 2013 at 6:27 PM, Morten Engvoldsen <mortenengv@gmail.com>wrote:

> Hi,
> My below code is wrong :
>
>
> 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
>
> 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:
>
> def is_valid_number(checknum):
>     weights = [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("123456785")
>
> This code validate this 9 digit number "123456785" with below algorithm:
>
>
> 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 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.
>
> Sorry for inconvience :(
>
>
>

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


Thread

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

csiph-web