Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python数字三元组_Python_Math - Fatal编程技术网

Python数字三元组

Python数字三元组,python,math,Python,Math,我想为毕达哥拉斯三胞胎写一个程序。用于数字的程序a,b,c返回毕达哥拉斯三个自然数a1,b1,c1,从而a1>=a,b1>=b,c1>=c def三元组(a、b、c): a1=a b1=b n=5 m=0 尽管如此: m+=1 b1问题在于,您已经注释掉了对c的不正确检查,但没有用任何内容替换它 如果您只是在返回之前添加该条件,则它会起作用: def Triplet(a,b,c): a1=a b1=b n=5 m=0 while True:

我想为毕达哥拉斯三胞胎写一个程序。用于数字的程序
a
b
c
返回毕达哥拉斯三个自然数
a1
b1
c1
,从而
a1>=a
b1>=b
c1>=c

def三元组(a、b、c): a1=a b1=b n=5 m=0 尽管如此: m+=1
b1问题在于,您已经注释掉了对c的不正确检查,但没有用任何内容替换它

如果您只是在返回之前添加该条件,则它会起作用:

def Triplet(a,b,c):
    a1=a
    b1=b
    n=5
    m=0
    while True:
        m+=1
        while b1<=(b+n*m):
            a1=a
            while a1<=b1:
                c1=(a1*a1+b1*b1)**.5
                if c1>=c and c1%1==0:
                    return a1,b1,int(c1)
                a1+=1
            b1+=1


print(Triplet(3,4,6))
def三元组(a、b、c): a1=a b1=b n=5 m=0 尽管如此: m+=1
而b1如果将条件更改为
如果c1%1==0和c1>=c:
,则问题将得到解决


我在本地运行它,得到了(6、8、10)

它现在提供了什么输出?当您单步执行代码时发现了什么?小的更正,应该是c1>=c。其他方面(3,4,5)的输入将给出(6,8,10),而不是(3,4,5)