jeudi 19 août 2021

Generate 4 digits number but excluding all the numbers with any 0

I would like to generate 4 digits random number in python but exclude all the numbers that have a "0" inside. For example, 9230, 2012 will not be accepted since there is a 0.

My code is:

def my_custom_random():
    exclude=[0]
    randInt = randint(1000, 9999)
    return my_custom_random() if randInt in exclude else randInt 

def Q3a():        
      RandomNumber = my_custom_random())  
      print(RandomNumber)
Q3a()

But this code is not working. Anyone can help me.




Aucun commentaire:

Enregistrer un commentaire