Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!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.078 X-Spam-Evidence: '*H*': 0.85; '*S*': 0.00; 'elif': 0.04; 'def': 0.10; 'int(x)': 0.16; 'subject:issue': 0.16; 'skip:i 40': 0.17; 'wrote': 0.26; 'message-id:@mail.gmail.com': 0.27; 'mod': 0.29; 'code': 0.31; 'could': 0.32; 'subject:Number': 0.33; 'to:addr:python- list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'false': 0.35; 'skip:. 20': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python.org': 0.39; 'skip:n 10': 0.63; 'validate': 0.65; '11:': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=WAru0QbtUGBg6yDwJYa1/aZ34/Uxp91XBzHoBpw4igM=; b=OJHjfcLBj3vO0kGKpc0n7idr+xIvZwt2pszawhTpYm8ErYFYmOPv4087JR0E4Ys95O 3fZ8RQdKDYLjcjH8fwV0R6tf+BLUO9P62N4bLuNpO23NpasyA80YzsCT+19to7y+jTpv V/WnopiJxNWqJpsloS6drZpNxdiO0zKNlz/iP6dCT/gcRoKjzssO/+mca+94fAQaTJxB kYSFJMtLpSsUeIHaUHyB+bpwIfAkEoQgxHTPA1Lj6IE6jespPj9FUuYObLaXKinFHoV4 Kdd5TbxpBQeFyOMw99RLZAZ0GbDDv8MDk8zu0ybihHoj5n0LYB9ry2BcwfWUolEPAXgG fAuw== MIME-Version: 1.0 X-Received: by 10.180.103.161 with SMTP id fx1mr49423507wib.25.1361545762501; Fri, 22 Feb 2013 07:09:22 -0800 (PST) Date: Fri, 22 Feb 2013 16:09:22 +0100 Subject: Number validation issue From: Morten Engvoldsen To: python-list@python.org Content-Type: multipart/alternative; boundary=f46d044288928509da04d6519359 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: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361545770 news.xs4all.nl 6955 [2001:888:2000:d::a6]:33375 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39577 --f46d044288928509da04d6519359 Content-Type: text/plain; charset=ISO-8859-1 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 --f46d044288928509da04d6519359 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi ,
I have wrote the below code to validate a number using modulus 10 a= nd 11:

def is_valid_number(checknum, mod):
=A0=A0=A0 if mod =3D= =3D 10:
=A0=A0=A0=A0=A0=A0=A0 if not len(checknum) >=3D 2 and len(che= cknum) <=3D25:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return False
=A0=A0=A0=A0=A0=A0=A0 number =3D tuple(int(i) for i in reversed(str(checknu= m)) )
=A0=A0=A0=A0=A0=A0=A0 return (sum(int(num) * 2 for num in number[1= ::2]) % 10) =3D=3D 0
=A0=A0=A0 elif mod =3D=3D 11:
=A0=A0=A0=A0=A0=A0= =A0 if not len(checknum)!=3D 11:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 retur= n False
=A0=A0=A0=A0=A0=A0=A0 weights =3D [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]
=A0= =A0=A0=A0=A0=A0=A0 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,=A0 Since for m= odulus 11 the weight should be in=A0
.............4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1=A0 in this format.= =A0

Could you please let me know how can i validate the 25 length n= umber for modulus 11 with weight ...............4,3,2,7,6, 5, 4, 3, 2, 7, 6= , 5, 4, 3, 2, 1=A0 in this format.

Regards,
Morten


--f46d044288928509da04d6519359--