def get_key(st):
s = st.replace('-', '')
x = sum((10-i-2) * int(s[i]) for i in range(7))
r = -x%11
last = str(r) if r != 10 else "X"
return last
def is_valid(st):
key = get_key(st)
return key == st[-1]
mickey = "2495-454"
print(get_key(mickey))
tests = ["0999-2138", "0397-1635", "2435-561X", "2434-561X"]
for test in tests:
print(is_valid(test))
To embed this program on your website, copy the following code and paste it into your website's HTML: