条件:
1.个十百位:从数字1/2/3/4中选择。
2.得到的三位数互不重复。例如,不能有两个124。
3.个十百位上的数字不重复。例如,不能包含数223。
def three_digit_number():
for i in range(1,5):
for j in range(1,5):
for k in range(1,5):
if i != j and i != k and j != k:
print(i,j,k)
排列组合问题:
C41×C31×C21=24
或者
C43×A33=24(先选后排)
另外一种比较霸气的:一句话实现,哈哈~~~
list_num = [1,2,3,4]
list = [i*100 + j*10 + k for i in list_num for j in list_num for k in list_num if (j != i and k != j and k != i)]
print (list)
另外一种方法:通过先列举然后排除法:
line=[]
for i in range(123,433):
a=i%10
b=(i%100)//10
c=(i%1000)//100
if a!=b and b!=c and a!=c and 0<a<5 and 0<b<5 and 0<c<5 :
print (i)
line.append(i)
print('the total is :',len(line))