Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

check if all the digits of the given number are different

I want to create a 4-digit number between 1000 and 10000 with different digits, but I am a bit inexperienced as I am new to this stuff. Can you help me?

import random

number = random.choice(range(1000,10000))


print(number)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import random

a = 0
while a == 0:
    a, b, c, d = random.sample(range(10), 4)
k = 1000*a + 100*b + 10*c + d
print(k)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading