我编写了这个程序,它输出总和为某个数字的毕达哥拉斯三元组(这将是参数)。该程序运行完美,但同一个三元组出现多次,我希望一个三元组只出现一次。我想知道是否有人可以帮助我。谢谢!
def pythagoreanCheck(tripletList):
'''
Checks whether the three numbers are pythagorean triplet
returns True or False
'''
trip_list = [0,1,2]
if tripletList[0]**2 + tripletList[1]**2 == tripletList[2]**2:
return True
else:
return False
def givMeSum(target):
'''
returns 3 numbers such that their sum is equal to target
'''
listOfa = xrange(1,target)
listOfb = xrange(1,target)
listOfc = xrange(1,target)
for i in listOfa:
for j in listOfb:
for k in listOfc:
add = i + j + k
if add == target:
add_list = [i,j,k]
add_list.sort()
value = pythagoreanCheck(add_list)
if value:
print add_list
def main():
givMeSum(12)
main()