Snippets

Zhiwei Li IMEI Check

Created by Zhiwei Li

File check_imei.py Added

  • Ignore whitespace
  • Hide word diff
+
+
+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')
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.