Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39577

Number validation issue

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 <mortenengv@gmail.com>
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 <mortenengv@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2272.1361545770.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Number validation issue Morten Engvoldsen <mortenengv@gmail.com> - 2013-02-22 16:09 +0100

csiph-web