APK errors

How to check the Azerbaijan IBAN sample

There is one number on this page: AZ84NABZ00000000137010002944. It is the calculation sample in the Central Bank's rule. It is not an account. No money is sent to it.

The second line is that same sample with only the last digit changed. That is not an account either.

The sample is 28 characters. AZ is the country. The next two digits are the check. Then come four letters. The remaining 20 characters are the account place. If it is short, zeros are written at the front.

The check follows ISO 7064, MOD 97-10. The first four characters move to the end. A letter becomes a number: A is 10, Z is 35. The resulting number is divided by 97. If the remainder is 1, the check digits are right. This does not show that an account exists.

NUMUNE = "AZ84NABZ00000000137010002944"
# Eyni nümunədir. Yalnız son rəqəm dəyişib. Hesab deyil.
POZUK = "AZ84NABZ00000000137010002945"

def qaliq(iban: str) -> int:
    metn = iban.replace(" ", "").upper()
    if not (len(metn) == 28 and metn.startswith("AZ")):
        raise ValueError("format")
    kecmis = metn[4:] + metn[:4]
    reqem = "".join(str(ord(h) - 55) if h.isalpha() else h for h in kecmis)
    return int(reqem) % 97

print(qaliq(NUMUNE))
print(qaliq(POZUK))