How do I make the randint
function not generate a specific list of numbers? I have to create a random bankcard code generator without it generating numbers with 4 repeated digits like '1111' '2222'.
import random
bank_codes = int(input("Hur många koder ska genereras: "))
code = 0
unwanted_codes = [0000, 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888, 9999]
while code < bank_codes:
code += 1
a = str(random.randint(1, 10000))
if len(a) == 3:
print('0' + a)
elif len(a) == 2:
print('00' + a)
elif len(a) == 1:
print('000' + a)
else:
print(a)
Aucun commentaire:
Enregistrer un commentaire