Python 百例--001

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 百例--001相关的知识,希望对你有一定的参考价值。

题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?

 

参照:http://www.runoob.com/python/python-exercise-example1.html

 

 1 [[email protected] test100]# cat 1.py 
 2 #!/usr/bin/python
 3 # -*- coding=utf-8 -*-
 4 
 5 list=[1,2,3,4]
 6 
 7 for i in range(4):
 8     for j in range(4):
 9         for k in range(4):
10             if list[i] != list[j] and list[i] != list[k] and list[j] != list[k]:
11                 print list[i]+list[j]+list[k]
12 [[email protected] test100]# python 1.py
13 123
14 124
15 132
16 134
17 142
18 143
19 213
20 214
21 231
22 234
23 241
24 243
25 312
26 314
27 321
28 324
29 341
30 342
31 412
32 413
33 421
34 423
35 431
36 432
37 [[email protected] test100]# 

 

以上是关于Python 百例--001的主要内容,如果未能解决你的问题,请参考以下文章