Created
April 14, 2016 20:07
-
-
Save pablovv72/4880ba52f18f42f626a3aa1cb6d5e1f6 to your computer and use it in GitHub Desktop.
ccc.py
This file contains 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
# coding: utf-8 | |
def dc_ok(ccc): | |
'''Chequea el dígito de control de una cuenta bancaria. | |
Entrada: ccc = str; Código Cuenta Bancaria (sin espacios). | |
Devuelve True si es correcto o False si es incorrecto.''' | |
suma = 0 | |
for i in range(8): | |
suma += int(ccc[i]) * (2 ** (i + 2) % 11) | |
suma = 11 - suma % 11 | |
digito_control = str((1 if suma == 10 else suma)) | |
suma = 0 | |
for i in range(10,20): | |
suma += int(ccc[i]) * (2 ** i % 11) | |
suma = 11 - suma % 11 | |
digito_control += str((1 if suma == 10 else suma)) | |
return (True if digito_control == ccc[8:10] else False) | |
def iban(ccc): | |
'''Calcula el IBAN correspondiente a una CCC. | |
Entrada: ccc = str; Código Cuenta Bancaria (sin espacios). | |
Devuelve una cadena del IBAN en grupos de 4 carácteres alfanuméricos | |
separados por espacios.''' | |
digitos_control = 98 - int(ccc + '142800') % 97 | |
ccc_formatado = '' | |
for i in range(0,20,4): | |
ccc_formatado += ccc[i:i+4] + (' ' if i < 16 else '') | |
return 'ES{0:02} {1}'.format(digitos_control, ccc_formatado) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment