# 1031 查验身份证python实现 (15分)

def NumPause(L,Wrong):#判断前17位是不是全为数字
for i in range(0,17):
if L[i] < '0' or L[i]>'9':
Wrong.append(L)
return 1
return 0
def CheckPause(L,Wrong):#判断是不是符合验证标准
M = L[17]
Weights = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
SumWeights = 0
Sum = 0
for i in range(0,17):
Sum += int(L[i])*int(Weights[i])
Z = Sum % 11
if Z == 0 and M != '1':
Wrong.append(L)
if Z == 1 and M != '0':
Wrong.append(L)
if Z == 2 and M != 'X':
Wrong.append(L)
if Z == 3 and M != '9':
Wrong.append(L)
if Z == 4 and M != '8':
Wrong.append(L)
if Z == 5 and M != '7':
Wrong.append(L)
if Z == 6 and M != '6':
Wrong.append(L)
if Z == 7 and M != '5':
Wrong.append(L)
if Z == 8 and M != '4':
Wrong.append(L)
if Z == 9 and M != '3':
Wrong.append(L)
if Z == 10 and M != '2':
Wrong.append(L)
N = int(input())
Wrong = []
for i in range(0,N):
L = input()
p = NumPause(L,Wrong)
if p == 0:
CheckPause(L,Wrong)
if len(Wrong) == 0:#如果所有号码都正常，则输出All passed。
print("All passed")
else:
for i in Wrong:
print(i)



©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试