Re: Number validation issue

Discussion in 'Python' started by Morten Engvoldsen, Feb 22, 2013.

  1. 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, so i have changed the
    code and sending again with correct code with valid number:

    def is_valid_number(checknum):
    weights = [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("123456785")

    This code validate this 9 digit number "123456785" with below algorithm:

    To verify the number use the following weights from right to left:
    1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7...
    Multiply each digit by its corresponding weight. Add the results together.
    For the number to be correct the
    total must be divisible by 11.
    Field with control digit 1 2 3 4 5 6 7 8 5
    Weight 3 2 7 6 5 4 3 2 1
    Produce +3 +4 +21 +24 +25 +24 +21 +16 +5 =143
    The sum must be divisible by 11 (143 divided by 11 leaves a remainder of
    0).

    So i am looking for solution how i can change this code to validate with
    weight 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7... from
    right to left for any length of number. This code validate only 9 digit
    number.

    Sorry for inconvience :(
    Morten Engvoldsen, Feb 22, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Morten Engvoldsen

    Number validation issue

    Morten Engvoldsen, Feb 22, 2013, in forum: Python
    Replies:
    0
    Views:
    74
    Morten Engvoldsen
    Feb 22, 2013
  2. Alec Taylor

    Re: Number validation issue

    Alec Taylor, Feb 22, 2013, in forum: Python
    Replies:
    0
    Views:
    88
    Alec Taylor
    Feb 22, 2013
  3. Alec Taylor

    Re: Number validation issue

    Alec Taylor, Feb 22, 2013, in forum: Python
    Replies:
    0
    Views:
    67
    Alec Taylor
    Feb 22, 2013
  4. Morten Engvoldsen

    Re: Number validation issue

    Morten Engvoldsen, Feb 22, 2013, in forum: Python
    Replies:
    0
    Views:
    81
    Morten Engvoldsen
    Feb 22, 2013
  5. Morten Engvoldsen

    Re: Number validation issue

    Morten Engvoldsen, Feb 22, 2013, in forum: Python
    Replies:
    0
    Views:
    83
    Morten Engvoldsen
    Feb 22, 2013
Loading...

Share This Page