Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'elif': 0.04; '[2]:': 0.09; 'len(x)': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'sat,': 0.15; 'int(x)': 0.16; 'shorthand': 0.16; 'subject:issue': 0.16; 'wrote:': 0.17; 'feb': 0.19; '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; 'am,': 0.27; 'prevent': 0.27; 'message-id:@mail.gmail.com': 0.27; 'mod': 0.29; 'url:mailman': 0.29; 'error': 0.30; '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; 'charset:windows-1252': 0.65; 'validate': 0.65; '11:': 0.84; '2013': 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:content-transfer-encoding; bh=vz+UqMc+tqyI+LTUiKXvyyoi75Uc2tQk6exeVRZAt+M=; b=Yqro2TFOBEzatbf7V7qc4mLg3bLToU2mqzQjD4zAa4R97oZX+RkRxO/Gn9QxHSeMl/ vQ8arjMHcuS6bUrDFjYjK121PC1lqZwVy9gxhl929Yth1XtZ80srceTnM1WKV+qwxf75 n21GgvmQdBj8oRcj2t6N5B/S9kC16A0M7sjb5bCgq/qTt8c2HSw6v/+Pd9AR27ukkXCA MPNfyF+yOMdoh7AaQJLzlhyhuzWzMCNMSRZXm0Tu30tMaUlf7VGo8BSxB2F/jvMFl0Wu t8HmxyipSCfL8OkRHXR8BCTtjI4wMLsjVcxQwnq52U+z4sp7HgutqwNFNUPDEB4eH1+N tR6g== MIME-Version: 1.0 X-Received: by 10.50.168.41 with SMTP id zt9mr1082987igb.42.1361547216205; Fri, 22 Feb 2013 07:33:36 -0800 (PST) In-Reply-To: References: Date: Sat, 23 Feb 2013 02:33:36 +1100 Subject: Re: Number validation issue From: Alec Taylor To: Morten Engvoldsen Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361547219 news.xs4all.nl 6858 [2001:888:2000:d::a6]:48189 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39580 Whoops, my mistake: In [5]: [not len(x) >=3D 2 and len(x)<=3D25 for x in [str(y) for y in xrang= e(30)]] Out [5]: [True]*10, [False]*20 But still, I'm guessing that's not the result you were looking for=85 On Sat, Feb 23, 2013 at 2:30 AM, Alec Taylor wrote= : > 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) >=3D 2 and len(x)<=3D25 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 =3D=3D 10: >> if not len(checknum) >=3D 2 and len(checknum) <=3D25: >> return False >> number =3D tuple(int(i) for i in reversed(str(checknum)) ) >> return (sum(int(num) * 2 for num in number[1::2]) % 10) =3D=3D 0 >> elif mod =3D=3D 11: >> if not len(checknum)!=3D 11: >> return False >> weights =3D [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] >> return (sum(w * int(x) for w, x in zip(weights, checknum)) % 11)= =3D=3D >> 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 modu= lus >> 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 >>