Last active
January 17, 2025 04:41
-
-
Save melizeche/daccaba7c841af01b327a1a3f72e6dd9 to your computer and use it in GitHub Desktop.
Calculo del dígito verificador del RUC en Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calcular_digito_verificador(numero: int, basemax: int = 11) -> int: | |
""" | |
Calcula el dígito verificador del RUC utilizando el algoritmo basado en el módulo 11. | |
Ref: https://www.dnit.gov.py/documents/20123/224893/D%C3%ADgito+Verificador.pdf/fb9f86c8-245d-9dad-2dc1-ac3b3dc307a7?t=1683343426554.pdf | |
Autor: Marcelo Elizeche Landó | |
Licencia: MIT | |
Args: | |
numero (int): Número base(CI o RUC sin DV) para calcular el dígito verificador. | |
basemax (int): Base máxima para los multiplicadores (por defecto 11, ver PDF de la DNIT). | |
Returns: | |
int: Dígito verificador calculado. | |
""" | |
numero_str = str(numero) | |
total = 0 | |
k = 2 | |
for digit in reversed(numero_str): | |
total += int(digit) * k | |
k = 2 if k == basemax else k + 1 | |
resto = total % 11 | |
return 11 - resto if resto > 1 else 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment