1,2,3,4,5这五个数字可以组成多少个不重复的三位数,请用一个列表把所有可能枚举出来,用python输出
时间: 2024-04-29 16:22:15 浏览: 71
python 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?(源码)
5星 · 资源好评率100%
可以使用嵌套的三重循环来实现:
```python
numbers = [1, 2, 3, 4, 5]
result = []
for i in numbers:
for j in numbers:
for k in numbers:
if i != j and i != k and j != k:
result.append(i*100+j*10+k)
print(result)
```
输出结果为:
```
[123, 124, 125, 132, 134, 135, 142, 143, 145, 152, 153, 154, 213, 214, 215, 231, 234, 235, 241, 243, 245, 251, 253, 254, 312, 314, 315, 321, 324, 325, 341, 342, 345, 351, 352, 354, 412, 413, 415, 421, 423, 425, 431, 432, 435, 451, 452, 453, 512, 513, 514, 521, 523, 524, 531, 532, 534, 541, 542, 543]
```
阅读全文