【发布时间】:2017-03-20 07:54:09
【问题描述】:
我需要一些关于学校项目代码的帮助。
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
有人可以帮我解决这个问题吗?谢谢!
【问题讨论】:
-
您的函数似乎设置为接受弧度作为输入,但您正在传递度数...