Skip to content

Instantly share code, notes, and snippets.

@MarcelaBarella
Created August 22, 2016 19:05
Show Gist options
  • Save MarcelaBarella/bf643e5682b9db3b1e8fccee7dc807a0 to your computer and use it in GitHub Desktop.
Save MarcelaBarella/bf643e5682b9db3b1e8fccee7dc807a0 to your computer and use it in GitHub Desktop.
cpf_1 = str(raw_input("Digite o cpf que deseja validar: "))
def Validar(cpf):
validadores1 = (10, 9, 8, 7, 6, 5, 4, 3, 2)
validadores2 = (11, 10, 9, 8, 7, 6, 5, 4, 3, 2)
aux = []
soma = 0
for i in cpf:
if(i != "." and i != "-" ):
aux.append(i)
for d in range(0,len(validadores1)):
soma += int(aux[d]) * validadores1[d]
if(soma % 11 > 2):
digit1 = 11 - (soma % 11)
else:
digit1 = 0
soma = 0
for e in range(0,len(validadores2)):
soma += int(aux[e]) * validadores2[e]
if(soma % 11 > 2):
digit2 = 11 - (soma % 11)
else:
digit2 = 0
if(aux[-1] == str(digit2) and aux[-2] == str(digit1)):
return "cpf valido"
else:
return "cpf invalido"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment