编写程序,输出由1、2、3、4、5、6这四个数字组成的每位数都不相同的所有四位数以及总个数。
x=set()
for i in range(1,7):
for j in range(1,7):
for k in range(1,7):
for l in range(1,7):
if i!=j and i!=k and i!=l and j!=k and j!=l and k!=l:
x.add(i*1000+j*100+k*10+l)
print(x)
print('总个数为:',len(x))
完整结果如下:
{6145, 6152, 6153, 6154, 4123, 4125, 4126, 4132, 4135, 4136, 4152, 4153, 4156, 4162, 4163, 4165, 6213, 6214, 6215, 2134, 2135, 2136, 6231, 6234, 6235, 2143, 2145, 2146, 6241, 6243, 6245, 2153, 2154, 6251, 2156, 6253, 6254, 2163, 2164, 2165, 4213, 4215, 4216, 4231, 4235, 4236, 4251, 4253, 4256, 4261, 4263, 6312, 4265, 6314, 6315, 6321, 6324, 6325, 6341, 6342, 6345, 6351, 6352, 6354, 4312, 4315, 4316, 4321, 4325, 4326, 4351, 4352, 4356, 4361, 2314, 2315, 2316, 4362, 4365, 6412, 6413, 6415, 6421, 6423, 6425, 6431, 6432, 6435, 2341, 2345, 2346, 2351, 2354, 6451, 2356, 6452, 6453, 2361, 2364, 2365, 2413, 2415, 2416, 6512, 6513, 6514, 6521, 6523, 6524, 2431, 2435, 2436, 6531, 6532, 6534, 6541, 6542, 6543, 2451, 2453, 2456, 2461, 2463, 4512, 2465, 4513, 4516, 4521, 4523, 4526, 4531, 4532, 4536, 2513, 2514, 4561, 2516, 4562, 4563, 2531, 2534, 2536, 2541, 2543, 2546, 2561, 2563, 2564, 4612, 4613, 4615, 4621, 4623, 4625, 4631, 4632, 4635, 4651, 4652, 4653, 2613, 2614, 2615, 2631, 2634, 2635, 2641, 2643, 2645, 2651, 2653, 2654, 5123, 5124, 5126, 5132, 5134, 5136, 5142, 5143, 5146, 5162, 5163, 5164, 3124, 3125, 3126, 3142, 3145, 3146, 3152, 3154, 3156, 3162, 3164, 3165, 5214, 5213, 5216, 5231, 5234, 5236, 5241, 5243, 5246, 5261, 3214, 3215, 3216, 5263, 5264, 3241, 3245, 3246, 3251, 3254, 3256, 3261, 3264, 3265, 5312, 5314, 5316, 5321, 5324, 5326, 1234, 1235, 1236, 1243, 1245, 1246, 5341, 5342, 5346, 1253, 1254, 1256, 1263, 1264, 1265, 5361, 5362, 5364, 5412, 5413, 5416, 1324, 1325, 1326, 5421, 5423, 5426, 5431, 5432, 5436, 1342, 1345, 1346, 1352, 1354, 1356, 1362, 1364, 1365, 3412, 3415, 3416, 5461, 5462, 5463, 3421, 3425, 3426, 3451, 3452, 3456, 3461, 3462, 3465, 1423, 1425, 1426, 1432, 1435, 1436, 1452, 1453, 1456, 1462, 1463, 3512, 1465, 3514, 3516, 3521, 3524, 3526, 3541, 3542, 3546, 3561, 3562, 3564, 5612, 5613, 5614, 1523, 1524, 5621, 1526, 5623, 5624, 1532, 1534, 5631, 1536, 5632, 5634, 1542, 1543, 5641, 1546, 5643, 5642, 1562, 1563, 1564, 3612, 3614, 3615, 3621, 3624, 3625, 3641, 3642, 3645, 3651, 3652, 3654, 1623, 1624, 1625, 1632, 1634, 1635, 1642, 1643, 1645, 1652, 1653, 1654, 6123, 6124, 6125, 6132, 6134, 6135, 6142, 6143}
总个数为: 360