2020-04-27

import string
digits_li = [dig for dig in range(1,10)]
lower_list = [word for word in string.ascii_lowercase]+[str(i) for i in digits_li]
digits_list = digits_li*3

word_dict = dict(zip(lower_list,digits_list[0:26]+digits_li))
word_dict["0"] = 0

def invi_code(code):
    code_li = list(code[::-1])
    # 翻转字符串,转换列表
    if len(code_li)!=16:
        return "error"
    odd_str = code_li[0::2]
    # 取出奇数位
    odd_sum = sum(word_dict.get(odd_s) for odd_s in odd_str)
    even_str = code_li[1::2]
    # 取出偶数位
    even_sum = sum(word_dict.get(even_s) for even_s in even_str)
    o_e_sum = odd_sum + even_sum
    return 'ok' if o_e_sum%10==0 else 'error'


a = invi_code("1234567890aq1212")
b = invi_code("123456op90aq1212")
c = invi_code("1234567890aq121")
print(a,b,c)

你可能感兴趣的:(2020-04-27)