import re
def validate(cpf: str) -> bool:
""" Valida o CPF """
# Verifica a formatação do CPF
if not re.match(r'\d{3}\.\d{3}\.\d{3}-\d{2}', cpf):
return False
numbers = [int(digit) for digit in cpf if digit.isdigit()]
# Verifica se o CPF possui 11 números:
if len(numbers) != 11:
return False
# Validação do primeiro dígito verificador:
sum_of_products = sum(a*b for a, b in zip(numbers[0:9], range(10, 1, -1)))
expected_digit = (sum_of_products * 10 % 11) % 10
if numbers[9] != expected_digit:
return False
# Validação do segundo dígito verificador:
sum_of_products = sum(a*b for a, b in zip(numbers[0:10], range(11, 1, -1)))
expected_digit = (sum_of_products * 10 % 11) % 10
if numbers[10] != expected_digit:
return False
return True
try:
cpf = '529.982.247-25'
assert validate(cpf), 'O CPF informado não é válido'
except AssertionError as error:
print(error)
aW1wb3J0IHJlCgpkZWYgdmFsaWRhdGUoY3BmOiBzdHIpIC0+IGJvb2w6CiAgICAiIiIgVmFsaWRhIG8gQ1BGICIiIgogICAgIyBWZXJpZmljYSBhIGZvcm1hdGHDp8OjbyBkbyBDUEYKICAgIGlmIG5vdCByZS5tYXRjaChyJ1xkezN9XC5cZHszfVwuXGR7M30tXGR7Mn0nLCBjcGYpOgogICAgICAgIHJldHVybiBGYWxzZQogICAgbnVtYmVycyA9IFtpbnQoZGlnaXQpIGZvciBkaWdpdCBpbiBjcGYgaWYgZGlnaXQuaXNkaWdpdCgpXQogICAgIyBWZXJpZmljYSBzZSBvIENQRiBwb3NzdWkgMTEgbsO6bWVyb3M6CiAgICBpZiBsZW4obnVtYmVycykgIT0gMTE6CiAgICAgICAgcmV0dXJuIEZhbHNlCiAgICAjIFZhbGlkYcOnw6NvIGRvIHByaW1laXJvIGTDrWdpdG8gdmVyaWZpY2Fkb3I6CiAgICBzdW1fb2ZfcHJvZHVjdHMgPSBzdW0oYSpiIGZvciBhLCBiIGluIHppcChudW1iZXJzWzA6OV0sIHJhbmdlKDEwLCAxLCAtMSkpKQogICAgZXhwZWN0ZWRfZGlnaXQgPSAoc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