Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Number validation issue

Reply
Thread Tools

Re: Number validation issue

 
 
Alec Taylor
Guest
Posts: n/a
 
      02-22-2013
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 <(E-Mail Removed)> 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 == 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
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Number validation issue Morten Engvoldsen Python 0 02-22-2013 05:27 PM
Re: Number validation issue Morten Engvoldsen Python 0 02-22-2013 04:40 PM
Re: Number validation issue Morten Engvoldsen Python 0 02-22-2013 04:32 PM
Re: Number validation issue Alec Taylor Python 0 02-22-2013 03:33 PM
Number validation issue Morten Engvoldsen Python 0 02-22-2013 03:09 PM



Advertisments