Design a function @busca_dni(lista)@ that, given a list
of DNI, checks whether all values are valid (that is, their letters
correspond to their numerations and they have the required length). The
function must return the first invalid DNI found, or str
ok if all are valid. You must use function
@check_letter(num, letra)@, which given an int
and a str
,
returns
if the letter corresponds with the number or
otherwise.
def check_letter(num, letra):
return letra == 'TRWAGMYFPDXBNJZSQVHLCKE'[num%23]
>>> busca_dni(['12345678Z', '98765432M']) 'ok' >>> busca_dni(['44556677A', '98765432M']) '44556677A' >>> busca_dni(['37485960P', '150150150', '13243546P']) '150150150' >>> busca_dni(['123456S', '13243546P']) '123456S' >>> busca_dni(['98765432M', '1234567890H']) '1234567890H'