[Solved] Python 3: How to get a random 4 digit number?
If you want to extend your solution to make sure the leading digit isn’t 0, there’s probably no super-concise way to write it; just be explicit: first = random.choice(range(1, 10)) leftover = set(range(10)) – {first} rest = random.sample(leftover, 3) digits = [first] + rest Notice that I’m taking advantage of the fact that sample takes … Read more