There are four numbers: 1, 2, 3, 4, how many three digits can be made up of each other without repeating numbers? What's the number?
Program Analysis:
Method One: The method is the answer on the Internet
First, iterate through all the three digits, fill in the hundred, 10 bits, digit digits are 1, 2, 3, 4, and then exclude the same and duplicate three digits.
>>> for I in range (1,5): for j in Range (1,5): for K in range (1,5): if (i!=j) and (J!=k) and (k!=i):p rint i,j,k1 2 31 2 41 3 21 3 41 4 21 4 32 1 32 1 42 3 12 3 42 4 12 4 33 1 23 1 43 2 13 2 43 4 13 4 24 1 24 1 34 2 14 2 34 3 14 3 2
Method Two: Based on method One, the result is treated as a three-digit number instead of a separate three-digit output, and the result is stored as a list:
>>> count=0>>> for I in range (1,5): for j in Range (1,5): for K in range (1,5): if (i!=j) and (J!=k) and (k!=i): s =0s=s+i*100+j*10+kl.append (s) count=count+1>>> print l[123, 124, 132, 134, 142, 143, 213, 214, 231, 234, 241, 243, 312, 314, 321, 324, 341, 342, 412, 413, 421, 423, 431, 432]>>> print count #计算各有几个三位数 >>> 24
Python instance One