python 编写程序输出50以内勾股数,如下图所示,要求每组显示六祖,各组勾股数无重复

import math
n = 0
for a in range(1,49):
    for b in range(a,49):
        c = math.ceil(math.sqrt(a**2+b**2))
        if c<50 and c**2 == a**2 + b**2:
            if(n%6 == 0):
            print("%2d,%2d,%2d"%(a,b,c),end='\t')
            n+=1

  

n = 0
for a in range(1,49):
    for b in range(a,49):
        for c in range(b,50):
            if a**2 + b**2 = c**2:
                if n%6==0 :
                    print()
                print("%2d,%2d,%2d"%(a,b,c),end=' ')
                n += 1

  

posted @ 2019-09-30 00:43  从前有座山,山上  阅读(3492)  评论(0编辑  收藏  举报