Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'algorithm': 0.03; 'python': 0.09; 'calculating': 0.09; 'subject:number': 0.09; 'subject:using': 0.09; 'advance': 0.10; 'def': 0.10; 'resulting': 0.13; '(result': 0.16; 'document:': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'isbn': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'multiplied': 0.16; 'structure.': 0.16; 'used."': 0.16; 'wrote:': 0.17; 'team,': 0.18; 'trying': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'url:cz': 0.29; 'url:download': 0.29; '"the': 0.29; 'becomes': 0.30; 'could': 0.32; '"")': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'thanks': 0.34; 'list': 0.35; 'false': 0.35; 'but': 0.36; 'method': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'apply': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'mentioned': 0.63; 'here': 0.65; 'validate': 0.65; 'account': 0.67; 'header:Reply- To:1': 0.68; 'banks': 0.71; 'reply-to:no real name:2**0': 0.72; '11.': 0.81; '(10': 0.84; '10th': 0.84; '2.7.': 0.84; 'reply- to:addr:python.org': 0.84; 'subject:Verification': 0.84; 'url:export': 0.84; 'norway': 0.91; 'divided': 0.93 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=XeZXOvF5 c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=Tv4_tr9OjFAA:10 a=ijs39f4QmqQA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=2VnhF_pZJooA:10 a=2TGC-hYiAAAA:8 a=dA8TSTLftYPf_gwNctsA:9 a=wPNLvfGTeEIA:10 a=6xdV7-7_Rw4A:10 a=wp5L4g_3z4U3wvSJ:21 a=gSlOR7Qpelhxda6L:21 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Tue, 19 Feb 2013 21:12:29 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Verification of bank number using modulus 11 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361308351 news.xs4all.nl 6925 [2001:888:2000:d::a6]:36330 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39278 On 2013-02-19 20:50, Morten Engvoldsen wrote: > Hi Team, > I am trying to verify the account number using the following algorithm: > > "The valid account number is 11 numeric digit without seperator. Eg. > 86011117947 is a valid account number. All banks apply a modulus-based > method for the validation of the account structure. The 10-digit account > number is multiplied from left to right by the following weights: 5, 4, > 3, 2, 7, 6, 5, 4, 3, 2. The resulting numbers are added up and divided > by 11. The remainder is subtracted from 11 and becomes the check digit. > If the remainder is 0, the check digit will be 0. If digits 5 and 6 of > the account number are zeros, the check digit is calculated on the 7, 8, > 9 and 10th digit of the account number. Account numbers for which the > remainder is 1 (check digit 10) cannot be used." > > I am trying to validate the Norway account number using the algorithm > mentioned in the following document: > http://www.cnb.cz/miranda2/export/sites/www.cnb.cz/cs/platebni_styk/iban/download/TR201.pdf > > Here is my code: > def calc_checkdigit(isbn): > isbn = isbn.replace(".", "") > check_digit = int(isbn[-1]) > isbn = isbn[:-1] > if len(isbn) != 10: > return False > result = sum((10 - i) * (int(x) if x != 'X' else 10) for i, x in enumerate(isbn)) > return (result % 11) == check_digit > > calc_checkdigit(""8601.11.17947"") > > In my program : it is calculating 10 digit with weights 10-1, but > according to above algorithm the weights should be : 5, 4, 3, 2, 7, 6, > 5, 4, 3, 2. > > Could you please let me know how can i calculate the 10 digit with > weights 5, 4, 3, 2, 7, 6, 5, 4, 3, 2. I am using python 2.7. > > Thanks in advance team for help.. > Put the weights into a list and use 'zip' instead of 'enumerate': sum(w * (10 if d == 'X' else int(d)) for w, d in zip(weights, isbn))