IBAN validation Python

4.6k Views Asked by At

For unitversity, we have to program a code, which validates the IBAN of Germany, Suisse and France. The German IBAN DE08700901001234567890 contains the two letters 'DE', the test number 08, the bank number 70090100 and the account number 1234567890. For letters you have to add +9 to his number (A = 10, B = 11,...Z = 35).

For validating an IBAN, the first four numbers have to be shifted to the end and the letters DE should be repleaced with 1314. The validation number 700901001234567890131408 Modul0 97 has to be 1.

We are absolute beginners. The topic of our lecture today was 'while- and for-loops', so the code needs to be easy. I assume, it has something to do with lists, because you add numbers, but we hadn't yet talked about lists in the lecture.

My attempt:

# add 9 to the letter
D = 13
E = 14
F = 15
R = 28
C = 12
H = 17

list = ibannummer = input ('Enter your IBAN number')
if 'DE' in ibannummer :
    banknumber = ibannummer[5,6,7,8,9,10,11] #banknumber 70090100
    accountumber = ibannummer[12:] #accountnummer 1234567890
    valiationnumber = bankleitzahl + kontonummer.append(ibannummer[0,1,2,3])
      if valiationnumber % 97 == 1 :
                        print ('validierte IBAN')
1

There are 1 best solutions below

0
thegamehugger On

This is just a temporary working theory based on what I understand:

IBAN = 'DE08700901001234567890'
if IBAN[0:2] == 'DE':
    testNumber = IBAN[2:4]
    bankNumber = IBAN[4:12]
    accNumber = IBAN[12:]
    valNumber= int("1314"+IBAN[6:]+IBAN[2:6])
    print(valNumber)
    if (valNumber%97)==1:
        print("This is a valid IBAN number")
    else:
        print("Excuse me sir, but this is not valid...")

this code however (if you give it a quick run) does not match up with your validation code you gave. If you wanted DE to be considered a number:

IBAN = 'DE08700901001234567890'
if IBAN[0:2] == 'DE':
    testNumber = IBAN[2:4]
    bankNumber = IBAN[4:12]
    accNumber = IBAN[12:]
    valNumber= int(bankNumber+accNumber+str(1314)+testNumber)
    print(valNumber)
    if (valNumber%97)==1:
        print("This is a valid IBAN number")
    else:
        print("Excuse me sir, but this is not valid...")

I don't see why you had to make all the letters = to a number (i.e D=13) since you check if it starts with DE, which you know is going to be 1314 no matter what.