Path: csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'elif': 0.04; '[2]:': 0.09; 'len(x)': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'int(x)': 0.16; 'subject:issue': 0.16; 'wrote:': 0.17; '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; 'wrote': 0.26; 'message- id:@mail.gmail.com': 0.27; 'mod': 0.29; 'url:mailman': 0.29; 'code': 0.31; 'url:python': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'subject:Number': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'false': 0.35; 'skip:. 20': 0.35; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'url:mail': 0.40; 'skip:n 10': 0.63; 'validate': 0.65; '11:': 0.84 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=88eS7LUEPwOMOiqcaPGaWAaTYz57pwzXRXm7eZWv4SQ=; b=r9y9enecXiB/SwucHxtLPh3vhoECGrWe1DLk1wiTr1pMPOO/kpU+FVR9ChK0XpeiMb lVONaE8d+5mNKo0GuQt9MJ+KhuHRjD8nvWpSzxs/duy+VZwcwzCVLxBrX5711UpILd0E iqDvme7MaagFgz0k5tLUZCezbyasHl5ydtPtD6Jactu1JdtIqpjs3yrnZvhimIlzc5G4 yVw9+00SI6KDH3PM30gfUDM77+STEXIDaXPVo2C53kXmKk5zrlN1VOtg+++zaTfWsgSF cgFsCiDciRjeoMEgtpA/lULZ19+teHiLWhe26xa75r9lclToZfNfBpzZzZxBJyr7/pEE OGBA== MIME-Version: 1.0 X-Received: by 10.50.37.236 with SMTP id b12mr15163313igk.42.1361547049480; Fri, 22 Feb 2013 07:30:49 -0800 (PST) In-Reply-To: References: Date: Sat, 23 Feb 2013 02:30:49 +1100 Subject: Re: Number validation issue From: Alec Taylor To: Morten Engvoldsen Content-Type: text/plain; charset=ISO-8859-1 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361547052 news.xs4all.nl 6987 [2001:888:2000:d::a6]:46298 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39579 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 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 >