python编写程序输出50以内勾股数,如下图所⽰,要求每组显
六祖,各组勾股数⽆重复
import math
n = 0
for a in range(1,49):
for b in range(a,49):
c = il(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
记住我