ValueError:数学域错误。。没有消极麻木的根源

2024-10-03 15:33:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我的python总是给我这个错误

没有负数的根,因为里面的所有位都是平方的。救命

    elif coordNumber == "4":
        fourInputXOne = int(input ("Please enter the x value of the first co-ordinate "))
        fourInputYOne = int(input ("Please enter the y value of the first co-ordinate "))
        print ("")
        fourInputXTwo = int(input ("Please enter the x value of the second co-ordinate "))
        fourInputYTwo = int(input ("Please enter the y value of the second co-ordinate "))
        print ("")
        fourInputXThree = int(input ("Please enter the x value of the third co-ordinate "))
        fourInputYThree = int(input ("Please enter the y value of the third co-ordinate "))
        print ("")
        fourInputXFour = int(input ("Please enter the x value of the fourth co-ordinate "))
        fourInputYFour = int(input ("Please enter the y value of the fourth co-ordinate "))
        print ("")

        print ("Here are the co-ordinates you have entered:")
        print ("1: (",fourInputXOne,",",fourInputYOne,")")
        print ("2: (",fourInputXTwo,",",fourInputYTwo,")")
        print ("3: (",fourInputXThree,",",fourInputYThree,")")
        print ("4: (",fourInputXFour,",",fourInputYFour,")")

        sideOneLength = math.sqrt((fourInputXTwo-fourInputXOne)^2 + (fourInputYTwo-fourInputYOne)^2 )
        sideTwoLength = math.sqrt((fourInputXThree-fourInputXTwo)^2 + (fourInputYThree-fourInputYTwo)^2 )
        sideThreeLength = math.sqrt((fourInputXFour-fourInputXThree)^2 + (fourInputYFour-fourInputYThree)^2 )
        sideFourLength = math.sqrt((fourInputXOne-fourInputXFour)^2 + (fourInputYOne-fourInputYFour)^2 )

边长位出错


Tags: oftheinputvalueintprintenterplease
2条回答

你为什么要逻辑地对你的价值观进行异或运算

打印有问题的数字:

print( (fourInputXTwo-fourInputXOne)^2 )   # you can see its negative

或试验:

print(6^2)       # prints 4  - because 0b110^0b010 == 0b100
print(6**2)      # prints 36 - because 6**2 = 6*6 = 36

会让你知道你做错了什么

有关完整文档,请参见binary bitwise operations

在python中,您使用a**b来平方非a^b

插入符号是一个二进制异或运算符

elif coordNumber == "4":
    fourInputXOne = int(input ("Please enter the x value of the first co-ordinate "))
    fourInputYOne = int(input ("Please enter the y value of the first co-ordinate "))
    print ("")
    fourInputXTwo = int(input ("Please enter the x value of the second co-ordinate "))
    fourInputYTwo = int(input ("Please enter the y value of the second co-ordinate "))
    print ("")
    fourInputXThree = int(input ("Please enter the x value of the third co-ordinate "))
    fourInputYThree = int(input ("Please enter the y value of the third co-ordinate "))
    print ("")
    fourInputXFour = int(input ("Please enter the x value of the fourth co-ordinate "))
    fourInputYFour = int(input ("Please enter the y value of the fourth co-ordinate "))
    print ("")

    print ("Here are the co-ordinates you have entered:")
    print ("1: (",fourInputXOne,",",fourInputYOne,")")
    print ("2: (",fourInputXTwo,",",fourInputYTwo,")")
    print ("3: (",fourInputXThree,",",fourInputYThree,")")
    print ("4: (",fourInputXFour,",",fourInputYFour,")")

    sideOneLength = math.sqrt((fourInputXTwo-fourInputXOne)**2 + (fourInputYTwo-fourInputYOne)**2 )
    sideTwoLength = math.sqrt((fourInputXThree-fourInputXTwo)**2 + (fourInputYThree-fourInputYTwo)**2 )
    sideThreeLength = math.sqrt((fourInputXFour-fourInputXThree)**2 + (fourInputYFour-fourInputYThree)**2 )
    sideFourLength = math.sqrt((fourInputXOne-fourInputXFour)**2 + (fourInputYOne-fourInputYFour)**2 )

相关问题 更多 >