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


Groups > comp.lang.python > #39595

Re: Number validation issue

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!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.064
X-Spam-Evidence '*H*': 0.87; '*S*': 0.00; 'elif': 0.04; 'cc:addr :python-list': 0.10; 'def': 0.10; '&gt;&gt;': 0.16; '0).': 0.16; 'int(x)': 0.16; 'left:': 0.16; 'subject:issue': 0.16; 'together.': 0.21; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'leaves': 0.29; 'mod': 0.29; 'code': 0.31; 'received:74.125.82': 0.33; 'subject:Number': 0.33; 'hi,': 0.33; 'skip:& 20': 0.33; 'changed': 0.34; 'received:google.com': 0.34; 'wrong': 0.34; 'false': 0.35; 'add': 0.36; 'received:74.125': 0.36; 'subject:: ': 0.38; 'number:': 0.65; 'results': 0.65; 'total': 0.65; 'validate': 0.65; 'sum': 0.66; '11.': 0.81; '11:': 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=nxrZdkU8FiOXCCGxfEBbkJENTRfrG5sG1QBVZANjl+k=; b=uWf+snuP+Fl8yIWyU5fAY3Ou83+PwFMDEl+69Yd7ITziKBDrMhFNJqridHakyu3mhA ecNFoGG2WO0tOF03kJUgdylV1z8z+eMsYOMlVthHzmBwICvk7vmz0Db7hf8xS0t1QSK/ ibwrghDkrWKDeU/SPDSQpyhVO6R6xv5HwPHXbmQ0jqp3ARKA+xK1kCRiX2PyUis98hAN FYppsj0tpCKwjAShQoLeKHLqC3XpFB5gSxxcub1jbC+uaAr21HRdtPZd3/RrthIeyDcF 4VuacO8TSM4I3CRXVVP7YFAkU7lqVYI6iTkqcLhCu2VXd/LKnsoCq9tHPZw3xk0wrcpJ Y/lw==
MIME-Version 1.0
X-Received by 10.194.157.42 with SMTP id wj10mr3136144wjb.12.1361554057286; Fri, 22 Feb 2013 09:27:37 -0800 (PST)
In-Reply-To <CAJ2vgs4YvQ+RcKMjEnSimRE3pv3QYbuHuSeHfnU703w1QJr5Ew@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> <CAJ2vgs4YvQ+RcKMjEnSimRE3pv3QYbuHuSeHfnU703w1QJr5Ew@mail.gmail.com>
Date Fri, 22 Feb 2013 18:27:37 +0100
Subject Re: Number validation issue
From Morten Engvoldsen <mortenengv@gmail.com>
To Alec Taylor <alec.taylor6@gmail.com>
Content-Type multipart/alternative; boundary=089e0112c512ed5d6404d653814f
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.2288.1361554059.2939.python-list@python.org> (permalink)
Lines 76
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361554059 news.xs4all.nl 6969 [2001:888:2000:d::a6]:42599
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39595

Show key headers only | View raw


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

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 18:27 +0100

csiph-web