1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
even = (10, 9, 8, 7, 6, 5, 4, 3, 2, 1) odd = (10, 8, 6, 4, 2, 9, 7, 5, 3, 1) def check_imei(imei): if len(imei) != 14: return 'X' checksum = 0 i = 0 for x in imei: c = int(x) if i%2 == 0: checksum = checksum + even[c] else: checksum = checksum + odd[c] checksum = checksum % 10 i = i + 1 return checksum print check_imei('35611812796672')
You can clone a snippet to your computer for local editing. Learn more.