How to find the unrepeatable combination of three digits in Python
This article will explain in detail how to find non-repetitive three-digit combinations in Python. The quality of the article is high, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.
Question: There are four numbers: 1, 2, 3 and 4. How many three-digit numbers can be formed without repeating numbers? How many are they?
Program analysis: can fill in hundreds, tens, digits are 1, 2, 3, 4. Make up all the permutations and then remove the permutations that do not meet the conditions.
for i in range(1,5): for j in range(1,5): for k in range(1,5): if( i != k ) and (i != j) and (j != k): print (i,j,k)
Please run in Python 3.
Program output:
1 2 31 2 41 3 21 3 41 4 21 4 32 1 42 3 12 3 42 4 12 4 33 1 23 1 43 2 13 4 24 1 24 1 34 2 14 3 2 How to find non-repeating three-digit combinations in Python is shared here. I hope the above content can be of some help to everyone and can learn more knowledge. If you think the article is good, you can share it so that more people can see it.