""" Validating the first 17 digits of an ID card number using the 18th digit. """
# Get a group of 18-digit ID card numbers from the console identification_number = input("Please enter an 18-digit ID card number: \n") # Declare an empty list array = [] # Put each character into the list for i in identification_number: array.append(i) # Convert the first 17 digits to integers for i inrange(17): array[i] = int(array[i]) # Perform multiplication and sum operation with the coefficients: 7-9-10-5-8-4-2-1-6-3-7-9-10-5-8-4-2 sum = array[0]*7 + array[1]*9 + array[2]*10 + array[3]*5 + array[4]*8 + array[5]*4 + array[6]*2 + array[7]*1 + array[8]*6 + array[9]*3 + array[10]*7 + array[11]*9 + array[12]*10 + array[13]*5 + array[14]*8 + array[15]*4 + array[16]*2 # Take the remainder of the sum divided by 11 remainder = sum%11 # Check if the remainder (0-10) corresponds to 1-0-X-9-8-7-6-5-4-3-2 if((remainder==0and array[17]=="1") \ or (remainder==1and array[17]=="0") \ or (remainder==2and array[17]=="X") \ or (remainder==3and array[17]=="9") \ or (remainder==4and array[17]=="8") \ or (remainder==5and array[17]=="7") \ or (remainder==6and array[17]=="6") \ or (remainder==7and array[17]=="5") \ or (remainder==8and array[17]=="4") \ or (remainder==9and array[17]=="3") \ or (remainder==10and array[17]=="2")): print("Validation successful") else: print("Validation failed")