Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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