Re: Number validation issue

2013-02-23 Thread Morten Engvoldsen
t; Cc: > Date: Fri, 22 Feb 2013 13:45:30 -0500 > Subject: Re: Number validation issue > On 02/22/2013 01:27 PM, Morten Engvoldsen wrote: > >> Hi, >> Just to make it more clear: I am looking for how to generate the weight >> in : >> 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6,

Re: Number validation issue

2013-02-22 Thread Dave Angel
On 02/22/2013 01:27 PM, Morten Engvoldsen wrote: Hi, Just to make it more clear: I am looking for how to generate the weight in : 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7.. format for any length of number instead of weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] only for fixed digi

Re: Number validation issue

2013-02-22 Thread Ian Kelly
On Fri, Feb 22, 2013 at 11:27 AM, Morten Engvoldsen wrote: > Hi, > Just to make it more clear: I am looking for how to generate the weight in : > 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7.. format for any > length of number instead of > > weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]

Re: Number validation issue

2013-02-22 Thread Morten Engvoldsen
Hi, Just to make it more clear: I am looking for how to generate the weight in : 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7.. format for any length of number instead of weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1] only for fixed digit. My below code can check only for 9 digit, so if

Re: Number validation issue

2013-02-22 Thread Morten Engvoldsen
Hi, My below code is wrong : 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 it works for 9 digit number , not 11 digit number,

Re: Number validation issue

2013-02-22 Thread Morten Engvoldsen
Hi, Just to clear the confusion: i am talking about below part of my code: 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 for w

Re: Number validation issue

2013-02-22 Thread Morten Engvoldsen
Hi, Thanks for your reply. Here in your code i think you didn't multiply the given number with the weight i have mentioned. The each digit of the given number should multiply with weight ...4,3,2,7,6, 5, 4, 3, 2, 7, 6, 5, 4, 3,2, 1 in this format. That is in detail: To verify the nu

Re: Number validation issue

2013-02-22 Thread Alec Taylor
Whoops, my mistake: In [5]: [not len(x) >= 2 and len(x)<=25 for x in [str(y) for y in xrange(30)]] Out [5]: [True]*10, [False]*20 But still, I'm guessing that's not the result you were looking for… 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

Re: Number validation issue

2013-02-22 Thread Alec Taylor
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 ha

Number validation issue

2013-02-22 Thread Morten Engvoldsen
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 (s