A legal ID card number consists of 17 digits of region, date number and sequence number plus 1 check code. The calculation rules of the check code are as follows:
First, the first 17 digits are weighted and summed, and the weight distribution is: {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}
; then the calculated sum is modulo 11 to obtain the value Z; finally, the Z value and the check code M value are corresponding according to the following relationship:
Z:0 1 2 3 4 5 6 7 8 9 10
M:1 0 X 9 8 7 6 5 4 3 2
Now given some ID numbers, please verify the validity of the check code and output the number in question.
Rules for verifying the validity of the ID card: (1) Whether the first 17 digits are all numbers; (2) The last 1-digit check code is calculated accurately.
Input format:
Enter a positive integer N (≤100) in the first line to indicate: the number of input ID numbers.
Then there are N lines, and each line gives a 18-digit ID card number.
Output format:
Output 1 problematic ID card number per line in the order of input.
If all numbers are normal, output All passed.
Input example 1:
4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
Output sample 1:
12010X198901011234
110108196711301866
37070419881216001X
Input example 2:
2
320124198808240056
110108196711301862
Sample output 2:
All passed
Code
n = int(input())
quanzhong = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
jiaoyanma = ['1','0','X','9','8','7','6','5','4','3','2']
flag = 0
for i in range(n):
jiaquanhe = 0
id = input()
if len(id) != 18:
flag += 1
print(id)
else:
f = 0
for j in range(17):
if id[j] in '0123456789':
f = f + 1
if f != 17:
flag += 1
print(id)
else:
for k in range(17):
jiaquanhe += quanzhong[k] * int(id[k])
if id[17] != jiaoyanma[jiaquanhe % 11]:
flag += 1
print(id)
if flag == 0:
print('All passed')
Submit results