Last active
February 5, 2021 08:36
-
-
Save canerbasaran/5935004 to your computer and use it in GitHub Desktop.
Validation of Turkish Identification Number in Python
TC Kimlik No Geçerlilik Kontrolü
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Copyright 2012 Caner BASARAN | |
# Licensed under the GNU General Public License, version 2. | |
# See the file http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt | |
def turkish_id_no_check(tc_no): | |
''' turkish_id_no_check(long) -> bool | |
Return the validation of Turkish Identification Number | |
>>> turkish_id_no_check(98768109974) | |
True | |
''' | |
list_tc = map(int,str(tc_no)) | |
tc10 = (sum(list_tc[0:10:2])*7 - sum(list_tc[1:9:2])) % 10 | |
tc11 = (sum(list_tc[0:9]) + tc10) % 10 | |
return True if list_tc[9] == tc10 and list_tc[10] == tc11 else False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I suggest you change line 18 because of this
from:
list_tc = map(int,str(tc_no))
To
list_tc = list(map(int,str(tc_no)))