题目:
有4个小朋友,2人一组,他们能分几组?
源码:
#!/usr/bin/env python3 #_*_ encoding:UTF-8 _*_ from itertools import combinations import sys print("\n"+" 小学数学 (二年级) ".center(70,"-")) print('''\n题目:\n\t有4个小朋友,2人一组,他们能分几组? \n答: \t总共能分 6 组\n \t分别是: (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4) \n''') print(" 请输入你要验证的人数 ".center(55,"-")) people_count = int(input("\n请输入总共有几个人: ")) people_team = int(input("请输入几人一组: ")) ## 总人数放入列表 data = [] for i in range(1,people_count+1): data.append(i) ## 分组 result = list(combinations(data , people_team)) ## 输出结果 print(f"\n总共能分 {len(result)} 组") print("\n分别是: ") for y in result: print(f"\t{y}")
-
-
__EOF__