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: 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; '>>': 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: References: Date: Fri, 22 Feb 2013 18:27:37 +0100 Subject: Re: Number validation issue From: Morten Engvoldsen To: Alec Taylor 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --089e0112c512ed5d6404d653814f Content-Type: text/plain; charset=ISO-8859-1 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 :( --089e0112c512ed5d6404d653814f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 digit n= umber, 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, c= hecknum)) % 11) =3D=3D 0

is_valid_number("123456785")
<= br>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 validate wit= h weight 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... from ri= ght to left for any length of number. This code validate only 9 digit numbe= r.

Sorry for inconvience :(


--089e0112c512ed5d6404d653814f--