def validate(code): yzm=['1','0','X','9','8','7','6','5','4','3','2'] xs=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2] s=0 for i,v in enumerate(code): s+=int(v)*xs[i] return yzm[s%11] if __name__=='__main__': cd = '34012320010101100' ret = validate(cd) print(ret)