Last active
January 10, 2018 00:45
-
-
Save dunossauro/bb13d898ef108de6902377647386e6ae to your computer and use it in GitHub Desktop.
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
""" | |
Minhas considerações a pergunta no facebook: | |
https://www.facebook.com/groups/python.brasil/permalink/1296198200485047/ | |
""" | |
def is_digit(func): | |
def inner(string): | |
if string.isdigit(): | |
return func(string) | |
return False | |
return inner | |
def mod_digit(dig: int, value: str) -> bool: | |
return 11 - (dig % 11) == int(value) | |
def verification_digits(str_cpf: str, aux: int) -> int: | |
total = 0 | |
for i in map(int, str_cpf): | |
if aux > 1: | |
total = (i * aux) + total | |
return total | |
@is_digit | |
def verification_cpf(str_cpf: str) -> bool: | |
dig_1 = verification_digits(str_cpf, 10) | |
dig_2 = verification_digits(str_cpf, 11) | |
if estado is str_cpf[:3]: | |
if mod_digit(dig_1, str_cpf[-2]) and mod_digit(dig_2, str_cpf[-1]): | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment