The Hong Kong Identity Card consists of 1 English letter and 6 numeric digits. A check digit, which could be 0 to 9 or A, is appended in brackets. It is calculated as follows:
For letters, A is converted to value 1, B to value 2, and so on.
For every HKID number LD1āD2āD3āD4āD5āD6ā, the sum is S=8L+7D1ā+6D2ā+5D3ā+4D4ā+3D5ā+2D6ā.
The check digit c shall be the smallest non-negative integer such that (s+c)%11=0. If c is 10, A is used instead.
Write a program to determine if the Identity Card is valid.
Input Format
A line which consists of the format LD1āD2āD3āD4āD5āD6ā(c).
Constraints
Aā¤Lā¤Z
0ā¤D1ā,D2ā,...D6āā¤9
0ā¤cā¤9,orĀ c=A
Output Format
Output 'YES' if the card is valid, otherwise, output 'NO'.
Sample Inputs:
Input
A123456(3)
Output
True
Input
C876300(0)
Output
false
Solution ā Trivial
just follow the steps, and make it as a warmup. The harder part is actually how to split the characters instead.
Here's the solution:
user_in = list(input())
user_in[0] = ord(user_in[0].upper()) - ord('A') + 1
if user_in[8] == 'A':
user_in[8] = 10
big_num = 8
sum = 0
for ins in range(7):
sum += big_num * int(user_in[ins])
big_num -= 1
if((sum + int(user_in[8])) % 11 == 0):
print("yes")
else:
print("no")