1.有 1、2、3、4 個數字,能組成多少個互不相同且無重複數字的三位數?都是多 少?
程式碼
1 #encoding=utf-8
2 __author__ = "heng"
3 #利用1,2,3,4可以組成多少個三位數,並且沒有重複數字
4 figure = [1,2,3,4]
5 number = 0
6 for x in figure:
7 for y in figure:
8 if x == y:
9 continue
10 else:
11 for z in figure:
12 if y == z or z == x: #注意是or不是and
13 continue
14 else:
15 number += 1
16 print 100*x + 10*y + z
17 print "the number is %s"%number
1.有 1、2、3、4 個數字,能組成多少個互不相同且無重複數字的三位數?都是多 少?
程式碼
1 #encoding=utf-8
2 __author__ = "heng"
3 #利用1,2,3,4可以組成多少個三位數,並且沒有重複數字
4 figure = [1,2,3,4]
5 number = 0
6 for x in figure:
7 for y in figure:
8 if x == y:
9 continue
10 else:
11 for z in figure:
12 if y == z or z == x: #注意是or不是and
13 continue
14 else:
15 number += 1
16 print 100*x + 10*y + z
17 print "the number is %s"%number