ich möchte nur eine gültige deutsche IBAN berechnen, aber bin dabei vor ein paar Rätsel gestellt worden:
Code: Alles auswählen
from random import randint
import string
LETTERS = {ord(d): str(i)
for i, d in enumerate(string.digits + string.ascii_uppercase)}
def _number_iban(iban):
return (iban[4:] + iban[:4]).translate(LETTERS)
def generate_iban_check_digits(iban):
number_iban = _number_iban(iban[:2] + '00' + iban[4:])
return '{:0>2}'.format(98 - (int(number_iban) % 97))
def valid_iban(iban):
return int(_number_iban(iban)) % 97 == 1
if __name__ == '__main__':
c = 0
cmax = 50000
nrmax = 10**10
print(nrmax)
my_checksum = input('Checksum (the first four characters): ')
my_blz = input('Bank code (8 digits): ')
my_example = ''
for i in range(0, cmax):
my_nr = '%010d' % randint(0, 9999999999)
my_iban = my_checksum + my_blz + my_nr
if (generate_iban_check_digits(my_iban) == my_iban[2:4] and valid_iban(my_iban)):
c += 1
if (c == 1):
my_example = my_iban
print('There are about {} account numbers for the checksum and the bank code {}. One of them is: {}.'.format(
(float(c)/cmax)*nrmax, my_checksum + my_blz, my_example))
Code: Alles auswählen
Checksum (the first four characters): DE34
Bank code (8 digits): 50010517
There are about 99000000.00000001 account numbers for the checksum and the bank code DE3450010517. One of them is: DE34500105170123598050.
Was hab ich übersehen? Vielen Dank fürs Proofreading.