Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CPF(object):
- numero = ""
- numeroComFormatacao = ""
- def __init__(self, cpf):
- self.numero = self.formatar(cpf)
- self.numeroComFormatacao = cpf
- def formatar(self, cpf):
- cpf = cpf.replace('-',"")
- cpf = cpf.replace('.',"")
- return cpf;
- def validar(self):
- return True if self.validarPrimeiroNumero() & self.validarSegundoNumero() else False
- def validarPrimeiroNumero(self, i = 10, y = 0, resultado = 0):
- while i >= 2:
- resultado += int(self.numero[y]) * i
- i -= 1
- y += 1
- return True if ((resultado*10) % 11) == int(self.numero[9]) else False
- def validarSegundoNumero(self, i = 11, y = 0, resultado = 0):
- while i >= 2:
- resultado += int(self.numero[y]) * i
- i -= 1
- y += 1
- return True if ((resultado*10) % 11) == int(self.numero[10]) else False
- cpf = CPF("529.982.247-25")
- if cpf.validar():
- print("O CPF {} é válido".format(cpf.numeroComFormatacao))
- else:
- print("O CPF {} é inválido".format(cpf.numeroComFormatacao))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement