Skip to content

Instantly share code, notes, and snippets.

@Gustavoo151
Created February 23, 2021 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gustavoo151/e766834c54505efccca6e9c95b06e870 to your computer and use it in GitHub Desktop.
Save Gustavoo151/e766834c54505efccca6e9c95b06e870 to your computer and use it in GitHub Desktop.
Validador de CPF
CPF = [5, 2, 9, 9, 8, 2, 2, 4, 7, 2, 5]
#Número 1 CPF
cont = cont2 = soma = soma2 = 0
*ult, n1, n2 = CPF
ulti_num2 = ([n1, n2])
mult = 10
for n1 in range(9):
soma += CPF[cont] * mult
cont += 1
mult -= 1
dig1 = 11 - (soma % 11)
if dig1 > 9:
digito1 = 0
else:
digito1 = dig1
# Número 2 CPF
mult = 11
for n2 in range(10):
soma2 += CPF[cont2] * mult
cont2 += 1
mult -= 1
digito2 = 11 - (soma2 % 11)
#VALIDAÇÃO
ulti_num = [digito1, digito2]
msg = 'Válido. ' if ulti_num == ulti_num2 else 'Inválido'
print(msg)
print(ulti_num, ulti_num2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment