Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.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错误bool对象没有属性';sqrt&x27;_Python - Fatal编程技术网

平方根python错误bool对象没有属性';sqrt&x27;

平方根python错误bool对象没有属性';sqrt&x27;,python,Python,我对python比较陌生,我正在尝试制作一个几何计算器,但是对于距离公式,需要平方根。但每当我尝试这样做时,就会出现以下错误: 回溯(最近一次呼叫最后一次): 文件“python”,第27行,在 AttributeError:“bool”对象没有属性“sqrt” 我真的非常感谢所有的帮助,以下是我的代码: math = True while math == True: Shape = input("GREETINGS HUMAN, I AM JERAXXUS EREDON LORD OF

我对python比较陌生,我正在尝试制作一个几何计算器,但是对于距离公式,需要平方根。但每当我尝试这样做时,就会出现以下错误: 回溯(最近一次呼叫最后一次): 文件“python”,第27行,在 AttributeError:“bool”对象没有属性“sqrt” 我真的非常感谢所有的帮助,以下是我的代码:

math = True
while math == True:
    Shape = input("GREETINGS HUMAN, I AM JERAXXUS EREDON LORD OF THE BURNING LEGION, what's your geometry question?")
    if Shape =='triangle':
        q1 = input("AREA OR PERIMETER?")
        if q1 == 'area':
            user_input = input("BASE AND HEIGHT PLZ, COMMAS INBETWEEN")
            X = str.split(user_input)
            print(X[0]*X[1]/2)
        if q1 == 'perimeter':
            q2 = input("do you have side lengths???")
            if q2 == 'yes':
                SL = input("please put in Side lengths")
                SL = str.split(SL)
                print(SL[0]+SL[1]+SL[2])
            if q2 == 'no':
                CD = input("Please put in coordinates")
                CD = str.split(CD)
                cd1 = int(CD[0])
                cd2 = int(CD[1])
                cd3 = int(CD[2])
                cd4 = int(CD[3])
                cd5 = int(CD[4])
                cd6 = int(CD[5])
                f1 = cd1^2*cd3^2+cd2^2*cd4^2
                f1 = int(f1)
                s1 = math.sqrt(f1)
                print(s1)

您将变量
math
指定为True(
math=True
),因此基本上覆盖了库
请尝试将其命名为其他名称。

导入数学库。然后可以使用sqrt函数。不要在应用程序中将库名称用作变量

import math

print math.sqrt(9) #it will print 3.0

1) 请修复您的缩进,这不是有效的Python。2) 不要用大写字母
S
命名变量
Shape
,将其命名为
Shape
。您已经用
math=True
隐藏了
math
模块(假设您曾经导入过它)。您已经定义了一个名为
math
的布尔型局部变量。将其重命名为其他名称。此外,将行
import math
添加到文件中。