Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.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.051 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'elif': 0.04; '22,': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; '>>': 0.16; '0).': 0.16; 'int(x)': 0.16; 'left:': 0.16; 'subject:issue': 0.16; 'wrote:': 0.17; 'feb': 0.19; 'email addr:gmail.com>': 0.20; '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; 'fixed': 0.28; 'leaves': 0.29; 'mod': 0.29; 'fri,': 0.30; 'code': 0.31; 'subject:Number': 0.33; 'hi,': 0.33; 'skip:& 20': 0.33; 'changed': 0.34; 'received:google.com': 0.34; 'wrong': 0.34; 'clear': 0.35; 'false': 0.35; 'pm,': 0.35; 'add': 0.36; 'subject:: ': 0.38; 'instead': 0.39; 'provide': 0.62; 'more': 0.63; 'number:': 0.65; 'results': 0.65; 'total': 0.65; 'validate': 0.65; 'sum': 0.66; '11.': 0.81; '11:': 0.84; '2013': 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=o5q2pdoHvK5yJwPKwxomFpS9tqMOUAoj2xbDzlclGiw=; b=Orc5LREl2oPkdZCrNNCRdgobwP+kf472yDQtekpxJyX0vvsGkaRc5n0iJitY49+xos xg+Bbrk1AoTw04Q15AYixxwWBO9ZhD+WQNtfZGreMGdWMSNW3cyuqWcw0ig8IiwejGHU nFHqakl42bbGStZG8igBitDLZrq4ouBcwxuZ3xGM9qfb23W1g1WKyXr8NA6zLTn238P4 dQAy13cf8zmiS7ZsIiHZPDyPYJprYwKl+tiwiMq+Y84Js/edbtFvtiUDMOdbgYJslQSV I0qEMbRwEBxwChq+8pofxN3OtGPKnfsYKcOYsWf+eMG6wFDJdlNjHU73vzPVeD/8Rtb5 x/0A== MIME-Version: 1.0 X-Received: by 10.194.157.42 with SMTP id wj10mr3493480wjb.12.1361557636358; Fri, 22 Feb 2013 10:27:16 -0800 (PST) In-Reply-To: References: Date: Fri, 22 Feb 2013 19:27:16 +0100 Subject: Re: Number validation issue From: Morten Engvoldsen To: Alec Taylor Content-Type: multipart/alternative; boundary=089e0112c51241adae04d6545765 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: 117 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361557644 news.xs4all.nl 6845 [2001:888:2000:d::a6]:45296 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39603 --089e0112c51241adae04d6545765 Content-Type: text/plain; charset=ISO-8859-1 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 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 :( > > > --089e0112c51241adae04d6545765 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,
Just to make it more clear: I am looking for how to generate the wei= ght in :
1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7..=A0 fo= rmat for any length of number instead of

weights =3D [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 th= at number. Hope, this makes clear what i am looking for...


On Fri, Feb 22, 2013 at 6:27 PM, Morten Engvoldsen <mortenengv@gmail.co= m> wrote:
Hi,
My below code is wrong :


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

it works for 9 digit number , not 11 d= igit number, so i have changed the code and sending again with correct code= with valid number:

def is_valid_number(checknum):
=A0=A0=A0 weights =3D [3, 2, 7, 6, 5,= 4, 3, 2, 1]

=A0=A0=A0 return (sum(w * int(x) for w, x= in zip(weights, checknum)) % 11) =3D=3D 0

is_valid_number(&qu= ot;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 = =3D143
The sum must be divisible by 11 (143 divided by 11 leaves a remai= nder of 0).

So i am looking for solution how i can change this code to valida= te with weight 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... f= rom right to left for any length of number. This code validate only 9 digit= number.

Sorry for inconvience :(



--089e0112c51241adae04d6545765--