验证18位身份证号码

阅读更多
#! /usr/bin/python
# -*- coding: utf-8 -*-

def check_id_num(id_num):
    assert len(id_num) == 18 and id_num[:17].isdigit()
    factors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
    remainders = ['1', '0', '*', '9', '8', '7', '6', '5', '4', '3', '2']
    result = sum([f*long(n) for f,n in zip(factors, id_num)])
    return remainders[result % 11] == id_num[-1]

你可能感兴趣的:(Python,F#)