标签:pytho and 复数 pre note char 结果 logs ==
问题:有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
#! /usr/bin/env python3 # -*- coding:utf-8 -*- # Author : Ma Yi # Blog : http://www.cnblogs.com/mayi0312/ # Date : 2020-06-18 # Name : demo001 # Software : PyCharm # Note : 有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少? # 入口函数 if __name__ == ‘__main__‘: temp_list = [1, 2, 3, 4] count = 0 for i in temp_list: for j in temp_list: for k in temp_list: if i != j and i != k and j != k: print(i, j, k) count += 1 print("Total count: %d" % count)
运行结果:
1 2 3
1 2 4
1 3 2
1 3 4
1 4 2
1 4 3
2 1 3
2 1 4
2 3 1
2 3 4
2 4 1
2 4 3
3 1 2
3 1 4
3 2 1
3 2 4
3 4 1
3 4 2
4 1 2
4 1 3
4 2 1
4 2 3
4 3 1
4 3 2
Total count: 24
标签:pytho and 复数 pre note char 结果 logs ==
原文地址:https://www.cnblogs.com/mayi0312/p/13157869.html