gpt4 book ai didi

Python-类型错误 : can't convert complex to float

转载 作者:太空宇宙 更新时间:2023-11-03 15:59:38 32 4
gpt4 key购买 nike

我需要一些有关学校项目代码的帮助。

import math

v = 9.412
g = 9.81
y = -1.5

def radToDeg(x):
return((x / math.pi) * 180)

def sqrt(x):
return(x ** 0.5)

def CalculateAngle(x):
return(radToDeg(math.atan(((v ** 2) + (sqrt((v ** 4) - (g * ((g * x ** 2) + (2 * y * v ** 2)))))) / (g * x))))

print(CalculateAngle(90.0297))

当我运行该程序时,我收到一个错误:

Traceback (most recent call last):
File "C:/Users/Owner/Desktop/ballista.py", line 16, in <module>
print(CalculateAngle(float(90.0297)))
File "C:/Users/Owner/Desktop/ballista.py", line 14, in CalculateAngle
return float(radToDeg(math.atan(((v ** 2) + (sqrt((v ** 4) - (g * ((g * x ** 2) + (2 * y * v ** 2)))))) / (g * x))))
TypeError: can't convert complex to float

有人可以帮我解决这个问题吗?谢谢!

最佳答案

引用这个ValueError: negative number cannot be raised to a fractional power

这可能会导致由于求幂优先于一元减号。

关于Python-类型错误 : can't convert complex to float,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40457263/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com