4.三色球
代码:
#!/usr/bin/env python # encoding: utf-8 """ @author: 侠之大者kamil @file: 26三色球.py @time: 2016/4/5 20:12 """ """ 12 个球 3 red 3 yel 6 blu 取8个,有多少搭配 """ def fun(): count=0 for i in range(4): for j in range(4): if 8 - i -j <=6: print(i,j,8 - i -j) count += 1 print(count) fun()
结果:
C:\Python34\python.exe D:/kamil/Documents/py/趣味百题/26三色球.py 0 2 6 0 3 5 1 1 6 1 2 5 1 3 4 2 0 6 2 1 5 2 2 4 2 3 3 3 0 5 3 1 4 3 2 3 3 3 2 13 Process finished with exit code 0
公众号请关注:侠之大者

浙公网安备 33010602011771号